package com.opd.soeghtool;


import android.Manifest;
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.AssetManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.hardware.usb.UsbManager;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.provider.Settings;
import android.support.annotation.RequiresApi;
import android.support.v4.app.NotificationCompat;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AbsoluteLayout;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.ScrollView;
import android.widget.SeekBar;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import org.json.JSONArray;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class ButtonSettingService extends Service {

    private final String TAG = "SOEBSS";

    WindowManager windowManager;
    WindowManager.LayoutParams paramsButtonSetting, paramsFloat, paramsAdvance, paramsDraw, paramsVirtualMacro,paramsVirtualMacroBG,paramsMacroEdit;
    MyBroadcastReceive myBroadcastReceive;
    MyDrawView myDrawView;
    ImageView iv_normal_btn[];
    ImageView iv_combo_btn[][];
    AbsoluteLayout btnFloatLayout,layout_btn_view, button_setting_layout, usercombin_layout,layout_advance_setting;
    LinearLayout layout_btn_setting_advance, ll_layout_btn_setting_advance_sub, layout_button_setting_add_remove;
    LinearLayout layout_btn_setting_adv_func_btn_action,layout_button_setting_macro_edit;
    LinearLayout layout_advance_setting_normal, layout_advance_setting_fps, layout_advance_setting_moba, layout_advance_setting_swipe, layout_advance_setting_macro, layout_advance_setting_quick_import;

    LinearLayout layout_button_setting_save, layout_button_setting_reset, layout_button_setting_visible, layout_button_setting_back,button_setting_macro_virtual_bg_layout;

    ImageView iv_btn_setting_float_visible, iv_btn_setting_advance_zoom,iv_button_setting_macro_virtual_bg,iv_btn_adv_range_bg;
    Button btn_btn_setting_guide, btn_btn_setting_advance_next, btn_btn_setting_advance_confirm, btn_btn_setting_test, btn_advance_setting_macro_virtual_set,btn_advance_setting_macro_btn_edit,btn_advance_setting_macro_virtual_edit;

    ImageView iv_advance_setting_btn, iv_btn_setting_ring, iv_button_setting_remove;
    TextView tv_advance_setting_title, tv_btn_setting_advance_tip, tv_btn_setting_advance_msg, tv_btn_setting_advance_detail, tv_btn_setting_float_visible;
    Button btn_advance_setting_cancel, btn_advance_setting_confirm;
    RadioButton rb_advance_setting_normal, rb_advance_setting_moba, rb_advance_setting_fps, rb_advance_setting_swipe, rb_advance_setting_macro, rb_advance_setting_quick_import;
    RadioButton rb_advance_setting_nor_single, rb_advance_setting_nor_combo, rb_advance_setting_nor_continue, rb_advance_setting_fps_pull, rb_advance_setting_moba_link, rb_advance_setting_moba_range,rb_advance_setting_moba_cancel;
    RadioButton rb_advance_setting_swipe_up, rb_advance_setting_swipe_down, rb_advance_setting_swipe_left, rb_advance_setting_swipe_right, rb_advance_setting_swipe_lu, rb_advance_setting_swipe_ld, rb_advance_setting_swipe_ru, rb_advance_setting_swipe_rd;
    RadioButton rb_advance_setting_macro_btn_quick, rb_advance_setting_macro_btn_adv, rb_advance_setting_macro_virtual;

    ListView lv_button_setting_macro_edit;
    ArrayList<Map<String, Object>> listData;
    MyEditAdapter myEditAdapter;
    int panelHeight, panelWidth;
    private int mImageHalfSize = 20, mImageHalfZoomUpSize = 40, mImgRingSize = 30;
    GlobalVar mGlobalVar;
    private int pttbl_temp[];
    private int combo_pttbl_temp[][];
    byte u8DataBuffer[];
    byte g_u8tAttrTable[][];
    byte g_u8TempAttrTable[];
    byte g_u8tAutoEventTbl[];
    byte g_u8TempAutoEventTbl[];
    byte g_u8AutoEventTblUsed;
    byte g_u8ActionTblStar = 0, g_u8ActionTblLen = 0;
    int g_u8ButtonID = 0, g_u8EVKey = 0;
    boolean bIsChanged = false, bIsShow = true, bIsRecordMacro = false, bIsEditBtn = false, bIsNeedCloseMenu = true;
    boolean bIsDrawViewOn = false, bIsAdvanceSettingOn = false, bIsBroadcastOn = false,bIsImageAlreadyCreate=false;
    boolean bIsSaveAutoEventTbl = false, bIsSaveAttrTable = false, bIsSubViewOn = true, bIsTestOn = false, bIsORIENTATION_PORTRAIT_mode = false;

    Handler settingHandler,handlerSystem;
    Message message2;

    int mMacroBtnStep = 0;
    int g_prvOrientation = 0;

    int mIconSizeBig = 0;
    int mBtnEditFlag = 0;
    int mBtnEditRecordingFlag = 0;
    int mBtnActionFlag = 0;
    byte mu8BtnAction = 0;

    int mAdvSettingStep1Index = 0;
    int mAdvSettingStep2Index = 0;

    int S2_X=0, S2_Y=0;


    @Override
    public void onCreate() {
        super.onCreate();
        WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        DisplayMetrics dm = new DisplayMetrics();
        display.getRealMetrics(dm);
        mGlobalVar = (GlobalVar) getApplication();
        mGlobalVar.setIsSettingServiceRunning(true);
        settingHandler = new Handler();

        pttbl_temp = new int[mGlobalVar.getDeviceMaxButton() * 2];
        combo_pttbl_temp = new int[4][mGlobalVar.getDeviceMaxButton() * 2];

        u8DataBuffer = new byte[Transfer_Con.HID_PACKET_SIZE];
        g_u8tAttrTable = new byte[mGlobalVar.getDeviceMaxButton()][3];
        g_u8TempAttrTable = new byte[3];
        g_u8tAutoEventTbl = new byte[Transfer_Con.MAX_AUTOEVENT_LENGTH];
        g_u8TempAutoEventTbl = new byte[Transfer_Con.MAX_AUTOEVENT_LENGTH];
        iv_normal_btn = new ImageView[Transfer_Con.APP_SUPPORT_MAX_BUTTON];
        iv_combo_btn = new ImageView[4][Transfer_Con.APP_SUPPORT_MAX_BUTTON-2];
        g_u8AutoEventTblUsed = 0;
        paramsFloat = new WindowManager.LayoutParams();
        paramsButtonSetting = new WindowManager.LayoutParams();
        paramsAdvance = new WindowManager.LayoutParams();
        paramsDraw = new WindowManager.LayoutParams();
        paramsVirtualMacro = new WindowManager.LayoutParams();
        paramsVirtualMacroBG = new WindowManager.LayoutParams();
        paramsMacroEdit = new WindowManager.LayoutParams();
        windowManager = (WindowManager) getApplication().getSystemService(Context.WINDOW_SERVICE);
        paramsMacroEdit.format = paramsVirtualMacroBG.format = paramsVirtualMacro.format = paramsDraw.format = paramsFloat.format = paramsAdvance.format = paramsButtonSetting.format = PixelFormat.RGBA_8888;

        paramsFloat.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        //paramsFloat.flags = WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM|WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        //paramsFloat.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
        //paramsFloat.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
        paramsMacroEdit.flags = paramsVirtualMacroBG.flags =paramsVirtualMacro.flags = paramsDraw.flags = paramsAdvance.flags = paramsButtonSetting.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;//|WindowManager.LayoutParams.FLAG_FULLSCREEN;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            paramsMacroEdit.type = paramsVirtualMacroBG.type = paramsVirtualMacro.type = paramsDraw.type = paramsFloat.type = paramsAdvance.type = paramsButtonSetting.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        } else {
            paramsMacroEdit.type = paramsVirtualMacroBG.type = paramsVirtualMacro.type = paramsDraw.type = paramsFloat.type = paramsAdvance.type = paramsButtonSetting.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            paramsMacroEdit.layoutInDisplayCutoutMode = paramsVirtualMacroBG.layoutInDisplayCutoutMode =paramsVirtualMacro.layoutInDisplayCutoutMode = paramsDraw.layoutInDisplayCutoutMode = paramsFloat.layoutInDisplayCutoutMode = paramsButtonSetting.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
        }
        //设置窗口初始停靠位置.
        paramsDraw.gravity = paramsFloat.gravity = paramsAdvance.gravity = paramsButtonSetting.gravity = Gravity.START | Gravity.TOP;


        Log.d(TAG, String.format("wid=%d, hei=%d", dm.widthPixels, dm.heightPixels));
        panelHeight = dm.heightPixels;
        panelWidth = dm.widthPixels;

        if (panelWidth < panelHeight) {
            int a = panelWidth;
            panelWidth = panelHeight;
            panelHeight = a;
            Log.d(TAG, "swap to Landscape Mode");
            bIsORIENTATION_PORTRAIT_mode = true;

        }
        if(Transfer_Con.ENABLE_DIFFERENT_RESOLUTION_GB) {

            mGlobalVar.tranSet_Value(Transfer_Con.HID_CMD_SET_SCREEN_RESOLUTION, panelWidth, panelHeight);
              /*
            if ((mGlobalVar.getScreenWidth() != panelHeight) && ((panelHeight == 1128) || (panelHeight == 752))) {
                panelHeight = mGlobalVar.getScreenWidth();
            }

            if ((mGlobalVar.getScreenHeight() != panelWidth) && ((panelWidth == 2400) || (panelWidth == 1600))) {
                panelWidth = mGlobalVar.getScreenHeight();
            }

             */
        }
        paramsButtonSetting.x = 0;
        paramsButtonSetting.y = 0;
        paramsButtonSetting.width = panelWidth;
        paramsButtonSetting.height = panelHeight;

        paramsVirtualMacroBG.x = 0;
        paramsVirtualMacroBG.y = 0;
        paramsVirtualMacroBG.width = panelWidth;
        paramsVirtualMacroBG.height = panelHeight;

        paramsDraw = paramsButtonSetting;
        paramsVirtualMacro = paramsDraw;
        paramsMacroEdit = paramsDraw;

        paramsFloat.x = panelWidth / 4;
        paramsFloat.y = 0;
        paramsFloat.width = dip2px(this, 155);
        paramsFloat.height = dip2px(this, 40);
        if(Transfer_Con.ENABLE_LANGUAGE_SWITCH) {
            Resources resources = getResources();
            Configuration config = resources.getConfiguration();
            //DisplayMetrics dm = resources.getDisplayMetrics();
            if (mGlobalVar.getCurLanguageIndex() == 0) {
                config.locale = Locale.getDefault();
                //上面是对应三种情况下设置三种语言设置
                //resources.updateConfiguration(config, dm);//刷新语言设置信息，这步不能少。
            } else if (mGlobalVar.getCurLanguageIndex() == 1)    // En
            {
                config.locale = Locale.ENGLISH;
                //上面是对应三种情况下设置三种语言设置
                //resources.updateConfiguration(config, dm);//刷新语言设置信息，这步不能少。
            } else if (mGlobalVar.getCurLanguageIndex() == 2)    // En
            {
                config.locale = Locale.CHINA;
                //上面是对应三种情况下设置三种语言设置
                //resources.updateConfiguration(config, dm);//刷新语言设置信息，这步不能少。
            }
            resources.updateConfiguration(config, dm);
        }
        LayoutInflater inflater = LayoutInflater.from(getApplication());
        button_setting_layout = (AbsoluteLayout) inflater.inflate(R.layout.button_setting_layout, null);
        layout_advance_setting = (AbsoluteLayout) inflater.inflate(R.layout.advance_setting_layout, null);
        btnFloatLayout = (AbsoluteLayout) inflater.inflate(R.layout.button_setting_float_layout, null);
        usercombin_layout = (AbsoluteLayout) inflater.inflate(R.layout.usercombin_layout, null);
        button_setting_macro_virtual_bg_layout = (LinearLayout) inflater.inflate(R.layout.button_setting_macro_virtual_bg_layout, null);
        layout_button_setting_macro_edit  = (LinearLayout) inflater.inflate(R.layout.button_setting_macro_edit_layout, null);
        myDrawView = new MyDrawView(this);

        myDrawView.bHasNotchScreen = mGlobalVar.getIsNotchFlag();
        myDrawView.screenWidth_Pass = mGlobalVar.getScreenHeight();
        myDrawView.screenHeight_Pass = mGlobalVar.getScreenWidth();
        if (!mGlobalVar.getIsAdvSetNeedGuide()) {
            windowManager.addView(myDrawView, paramsDraw);
            bIsDrawViewOn = true;
        }




        windowManager.addView(button_setting_layout, paramsButtonSetting);
        windowManager.addView(btnFloatLayout, paramsFloat);

        if(Transfer_Con.ENABLE_GAME_DATA_IN_PHONE_GP)
        {
            for (int k = 0; k < mGlobalVar.getDeviceMaxButton(); k++) {
                for(int a=0;a<3;a++)
                    g_u8tAttrTable[k][a]= (byte)mGlobalVar.attrTbl[k][a];

                //Log.d(TAG,String.format("%x,%x,%x",g_u8tAttrTable[k][0],g_u8tAttrTable[k][1],g_u8tAttrTable[k][2]));
            }
            //System.arraycopy(mGlobalVar.attrEvTbl,0,g_u8tAutoEventTbl,0,Transfer_Con.MAX_AUTOEVENT_LENGTH);
            for (int k = 0; k < Transfer_Con.MAX_AUTOEVENT_LENGTH; k++)
            {
                g_u8tAutoEventTbl[k] = (byte)mGlobalVar.attrEvTbl[k];
            }
        }
        else {
            for (int a = 0; a < Transfer_Con.MAX_AUTOEVENT_LENGTH; a += 30) {
                if (mGlobalVar.tranGet_Value(Transfer_Con.HID_CMD_GET_AEV_TBL, a, (a + 30 >= Transfer_Con.MAX_AUTOEVENT_LENGTH) ? (Transfer_Con.MAX_AUTOEVENT_LENGTH - a) : 30, u8DataBuffer)) {
                    System.arraycopy(u8DataBuffer, 16, g_u8tAutoEventTbl, a, (a + 30 >= Transfer_Con.MAX_AUTOEVENT_LENGTH) ? (Transfer_Con.MAX_AUTOEVENT_LENGTH - a) : 30);
                }
            }
            for (int a = 0; a < 3; a++) {
                if (mGlobalVar.tranGet_Value(Transfer_Con.HID_CMD_GET_KEY_ATTR, a, 0, u8DataBuffer)) {
                    for (int k = 0; k < mGlobalVar.getDeviceMaxButton(); k++) {
                        g_u8tAttrTable[k][a] = u8DataBuffer[16 + k];
                    }
                }
            }
        }
        for (int k = 0; k < mGlobalVar.getDeviceMaxButton(); k++) {
            if ((g_u8tAttrTable[k][0] & Transfer_Con.ATTR_MASK) != 0) {
                if ((g_u8tAttrTable[k][1] & 0xff) >= (g_u8AutoEventTblUsed & 0xFF)) {
                    g_u8AutoEventTblUsed = (byte) ((g_u8tAttrTable[k][1] & 0xFF) + (g_u8tAttrTable[k][2] & 0xFF));

                    if (BuildConfig.DEBUG)
                        Log.d(TAG, String.format("%s s=%d,l=%d,used=%d", Transfer_Con.tButtonName[k], g_u8tAttrTable[k][1], g_u8tAttrTable[k][2], g_u8AutoEventTblUsed & 0xFF));
                }
            }
        }
        subLayout();
        advanceSettingInitial();

       // Log.d(TAG, "getIsAdvSetNeedGuide " + String.valueOf(mGlobalVar.getIsAdvSetNeedGuide()));
       // Log.d(TAG, "getIsEnterGameNeedGuide " + String.valueOf(mGlobalVar.getIsEnterGameNeedGuide()));


        showAddandRemove();
        myBroadcastReceive = new MyBroadcastReceive();
//注册广播接收,注意：要监听这个系统广播就必须用这种方式来注册，不能再xml中注册，否则不能生效
        IntentFilter filter = new IntentFilter();
        filter.addAction("android.intent.action.CONFIGURATION_CHANGED");
        filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
        filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
        filter.addAction("com.opd.soeghtool.content");
        registerReceiver(myBroadcastReceive, filter);
        bIsBroadcastOn = true;

        Configuration mConfiguration = this.getResources().getConfiguration(); //获取设置的配置信息
        g_prvOrientation = mConfiguration.orientation;
        if ((Configuration.ORIENTATION_PORTRAIT == mConfiguration.orientation) && bIsORIENTATION_PORTRAIT_mode) {
            Log.d(TAG, "ORIENTATION_PORTRAIT Hide Win");
            stopAndGoBack();
        } else {
            // User Guide
            if (mGlobalVar.getIsAdvSetNeedGuide()) {
                mGlobalVar.setIsEnterAdvGuide(true);
                Intent intent = new Intent(ButtonSettingService.this, UserGuideService.class);
                startService(intent);
            }
        }

        if(Transfer_Con.ENABLE_OPPO_MSG_HANDLE) {
            if (android.os.Build.BRAND.equalsIgnoreCase("OPPO")) {
                handlerSystem = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        super.handleMessage(msg);

                        Configuration mConfiguration = ButtonSettingService.this.getResources().getConfiguration(); //获取设置的配置信息
                        if (g_prvOrientation != mConfiguration.orientation) {
                            g_prvOrientation = mConfiguration.orientation;
                            if (Configuration.ORIENTATION_PORTRAIT == mConfiguration.orientation) {
                                Log.d(TAG, "ORIENTATION_PORTRAIT");
                                stopAndGoBack();
                            }
                        }

                        if (mGlobalVar.isUSBDeviceListEmpty()) {
                            Log.d(TAG, "USB Disconnect");
                            if (mGlobalVar.getbIsUsbConnect()) {
                                mGlobalVar.setbIsUsbConnect(false);
                                mGlobalVar.setbIsTransferMode(false);
                                mGlobalVar.myUsbDevice = null;
                                mGlobalVar.myInterface = null;
                                mGlobalVar.epOut = null;
                                mGlobalVar.epIn = null;
                                if(Transfer_Con.ENABLE_OPPO_MSG_HANDLE) {
                                    if (android.os.Build.BRAND.equalsIgnoreCase("OPPO")) {
                                        mGlobalVar.setIsFloatServiceRunning(false);
                                    }
                                }
                                stopSelf();
                            }
                        }
                        message2 = handlerSystem.obtainMessage();
                        message2.what = 0;
                        message2.arg1 = 1;
                        message2.arg2 = 2;
                        handlerSystem.sendMessageDelayed(message2, 5000);//MENU_STAY_TIME);
                    }
                };
            }
        }
        if(Transfer_Con.ENABLE_OPPO_MSG_HANDLE) {
            if (android.os.Build.BRAND.equalsIgnoreCase("OPPO")) {
                message2 = handlerSystem.obtainMessage();
                message2.what = 0;
                message2.arg1 = 1;
                message2.arg2 = 2;
                handlerSystem.sendMessageDelayed(message2, 5000);//MENU_STAY_TIME);
            }
        }

        if (Transfer_Con.ENABLE_OPPO_FOREGROUND_SERVICE) {
            if (android.os.Build.BRAND.equalsIgnoreCase("OPPO")) {
                if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                    createNotificationChannel();
                }
            }
        }
    }

    private static final String CHANNEL_ID = "com.opd.soeghtool";
    @RequiresApi(api = Build.VERSION_CODES.O)
    private void createNotificationChannel() {
        //设定的通知渠道名称
        String channelName = getString(R.string.app_name);
        //设置通知的重要程度
        int importance = NotificationManager.IMPORTANCE_LOW;
        //构建通知渠道
        NotificationChannel channel = new NotificationChannel(CHANNEL_ID, channelName, importance);
        channel.setDescription("手易悬浮窗正在运行");
        //在创建的通知渠道上发送通知
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID);
        builder.setSmallIcon(R.drawable.round_background) //设置通知图标
                .setContentTitle("手易")//设置通知标题
                .setContentText("手易悬浮窗正在运行")//设置通知内容
                .setAutoCancel(true) //用户触摸时，自动关闭
                .setOngoing(true);//设置处于运行状态
        //向系统注册通知渠道，注册后不能改变重要性以及其他通知行为
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(channel);
        //将服务置于启动状态 NOTIFICATION_ID指的是创建的通知的ID
        startForeground(113, builder.build());
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }


    @SuppressLint("ClickableViewAccessibility")
    void subLayout() {

        iv_btn_setting_float_visible = (ImageView) btnFloatLayout.findViewById(R.id.iv_btn_setting_float_visible);
        //iv_btn_setting_float_back = (ImageView) btnFloatLayout.findViewById(R.id.iv_btn_setting_float_back);
        tv_btn_setting_float_visible = (TextView) btnFloatLayout.findViewById(R.id.tv_btn_setting_float_visible);
        layout_button_setting_visible = (LinearLayout) btnFloatLayout.findViewById(R.id.layout_button_setting_visible);
        layout_button_setting_back = (LinearLayout) btnFloatLayout.findViewById(R.id.layout_button_setting_back);
        //iv_button_setting_reset = (ImageView) button_setting_layout.findViewById(R.id.iv_button_setting_reset);
        //iv_button_setting_save = (ImageView) button_setting_layout.findViewById(R.id.iv_button_setting_save);

        layout_button_setting_reset = (LinearLayout) btnFloatLayout.findViewById(R.id.layout_button_setting_reset);
        layout_button_setting_save = (LinearLayout) btnFloatLayout.findViewById(R.id.layout_button_setting_save);

        btn_btn_setting_guide = (Button) button_setting_layout.findViewById(R.id.btn_btn_setting_guide);
        btn_btn_setting_test = (Button) button_setting_layout.findViewById(R.id.btn_btn_setting_test);
        iv_button_setting_remove = (ImageView) button_setting_layout.findViewById(R.id.iv_button_setting_remove);


        btn_btn_setting_advance_next = (Button) button_setting_layout.findViewById(R.id.btn_btn_setting_advance_next);
        btn_btn_setting_advance_confirm = (Button) button_setting_layout.findViewById(R.id.btn_btn_setting_advance_confirm);
        iv_btn_setting_advance_zoom = (ImageView) button_setting_layout.findViewById(R.id.iv_btn_setting_advance_zoom);
        iv_btn_setting_ring = (ImageView) button_setting_layout.findViewById(R.id.iv_btn_setting_ring);
        tv_btn_setting_advance_tip = (TextView) button_setting_layout.findViewById(R.id.tv_btn_setting_advance_tip);
        tv_btn_setting_advance_msg = (TextView) button_setting_layout.findViewById(R.id.tv_btn_setting_advance_msg);


        layout_button_setting_visible.setX(0);
        layout_button_setting_visible.setY(0);
        layout_button_setting_back.setX(layout_button_setting_visible.getX() + dip2px(this, 40));
        layout_button_setting_back.setY(0);

        if(Transfer_Con.ENABLE_S2_MENU_COVER&&(mGlobalVar.getIsForceS2Enable()))
        {

        }
        else
        {
            if (Transfer_Con.ENABLE_S2_QUICK_MENU || Transfer_Con.ENABLE_GN_LOGO_QUICK_MENU) {
                if (mGlobalVar.getIsSupportMenuKey()) {
            int x = (paramsFloat.x + (int) layout_button_setting_back.getX() + 1) * 0x7FFF / panelWidth;
            int y = 0x7FFF / panelHeight;
            mGlobalVar.menuOnPos_x = x;
            mGlobalVar.menuOnPos_y = y;
            mGlobalVar.tranSet_Value(Transfer_Con.HID_CMD_SET_MENU_POS, 1, (x << 16) | y);
        }
    }
}
        layout_button_setting_reset.setX(layout_button_setting_back.getX() + dip2px(this, 40));
        layout_button_setting_reset.setY(0);

        iv_button_setting_remove.setX(layout_button_setting_reset.getX());
        iv_button_setting_remove.setY(dip2px(this, 50));

        //iv_button_setting_save.setX(iv_button_setting_reset.getX()+dip2px(this,40));
        //iv_button_setting_save.setY(0);
        layout_button_setting_save.setX(layout_button_setting_reset.getX() + dip2px(this, 40));
        layout_button_setting_save.setY(0);

        btn_btn_setting_test.setX(panelWidth/2);
        btn_btn_setting_test.setY(0);
        btn_btn_setting_guide.setX(btn_btn_setting_test.getX() + dip2px(this, 65));
        btn_btn_setting_guide.setY(0);

        layout_button_setting_back.setOnClickListener(onClickListener);
        layout_button_setting_visible.setOnClickListener(onClickListener);
        layout_button_setting_reset.setOnClickListener(onClickListener);
        layout_button_setting_save.setOnClickListener(onClickListener);
        btn_btn_setting_guide.setOnClickListener(onClickListener);
        btn_btn_setting_test.setOnClickListener(onClickListener);
        btn_btn_setting_advance_next.setOnClickListener(onClickListener);
        btn_btn_setting_advance_confirm.setOnClickListener(onClickListener);
        iv_btn_setting_advance_zoom.setOnClickListener(onClickListener);
        layout_btn_setting_adv_func_btn_action = (LinearLayout) button_setting_layout.findViewById(R.id.layout_btn_setting_adv_func_btn_action);

        mImageHalfSize = (int)(((float)dip2px(this,20)*(mGlobalVar.getPt_Tbl_View_Size() + 5) / 10));
        mImageHalfZoomUpSize = mImageHalfSize * 2;

        ViewGroup.LayoutParams ring_lp = iv_btn_setting_ring.getLayoutParams();
        iv_btn_setting_ring.setAlpha(((float) mGlobalVar.getPt_Tbl_View_Alpha()) / 10);
        ring_lp.width = (int) (ring_lp.width * (((float) mGlobalVar.getPt_Tbl_View_Size() + 5) / 10));
        ring_lp.height = (int) (ring_lp.height * (((float) mGlobalVar.getPt_Tbl_View_Size() + 5) / 10));
        mImgRingSize = ring_lp.height / 2;

        layout_btn_view = (AbsoluteLayout) button_setting_layout.findViewById(R.id.layout_btn_view);
        layout_btn_setting_advance = (LinearLayout) button_setting_layout.findViewById(R.id.layout_btn_setting_advance);
        ll_layout_btn_setting_advance_sub = (LinearLayout) button_setting_layout.findViewById(R.id.ll_layout_btn_setting_advance_sub);

        layout_button_setting_add_remove = (LinearLayout) button_setting_layout.findViewById(R.id.layout_button_setting_add_remove);

        //layout_btn_view.setVisibility(View.GONE);
        ViewGroup.LayoutParams adv_lp = layout_btn_setting_advance.getLayoutParams();
        layout_btn_setting_advance.setX((int) (panelWidth / 4));
        layout_btn_setting_advance.setY(dip2px(this, 40));
        adv_lp.width = (int) (panelWidth / 2);
        adv_lp.height = (int) (panelHeight / 2);
        showFloatImage();

        button_setting_layout.setOnTouchListener(new View.OnTouchListener() {
            int prevX, prevY;

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        prevX = (int) event.getRawX();
                        prevY = (int) event.getRawY();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        break;
                    case MotionEvent.ACTION_UP:
                        //Log.d(TAG,String.format("bbbbbbbbbbbbbbbbbbbbb x=%d y=%d; l=%d,r=%d,t=%d,b=%d",prevX,prevY,(int)(paramsFloat.x + layout_button_setting_back.getX()),(int)(paramsFloat.x + layout_button_setting_back.getX() + layout_button_setting_back.getWidth()),(int)(paramsFloat.y + layout_button_setting_back.getY()),(int)(paramsFloat.y + layout_button_setting_back.getY() + layout_button_setting_back.getHeight())));
                        if ((Math.abs(prevX - (int) event.getRawX())<=10) && (Math.abs(prevY - (int) event.getRawY())<=10)) {
                            if ((prevX >= paramsFloat.x + layout_button_setting_visible.getX()) && ((prevX <= paramsFloat.x + layout_button_setting_visible.getX() + layout_button_setting_visible.getWidth()))
                                    && (prevY >= paramsFloat.y + layout_button_setting_visible.getY()) && (prevY <= (paramsFloat.y + layout_button_setting_visible.getY() + layout_button_setting_visible.getHeight()))) {
                                layout_button_setting_visible.performClick();
                            } else if ((prevX >= paramsFloat.x + layout_button_setting_back.getX()) && (prevX <= paramsFloat.x + layout_button_setting_back.getX() + layout_button_setting_back.getWidth())
                                    && (prevY >= paramsFloat.y + layout_button_setting_back.getY()) && (prevY <= paramsFloat.y + layout_button_setting_back.getY() + layout_button_setting_back.getHeight())) {
                               // Log.d(TAG,String.format("aaaaaaaaaaaaaaaaaaaaaa x=%d y=%d; l=%d,r=%d,t=%d,b=%d",prevX,prevY,(int)(paramsFloat.x + layout_button_setting_back.getX()),(int)(paramsFloat.x + layout_button_setting_back.getX() + layout_button_setting_back.getWidth()),(int)(paramsFloat.y + layout_button_setting_back.getY()),(int)(paramsFloat.y + layout_button_setting_back.getY() + layout_button_setting_back.getHeight())));
                                layout_button_setting_back.performClick();
                            }

                        }
                        break;
                }
                return false;
            }
        });
        btnFloatLayout.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_MENU) {
                    if (mGlobalVar.getIsAdvSetNeedGuide()) {
                        Intent stopIntent = new Intent(ButtonSettingService.this, UserGuideService.class);
                        stopService(stopIntent);
                    }
                    layout_button_setting_back.performClick();
                }
                return false;
            }
        });

    }

    public static int dip2px(Context context, float dipValue) {
        final float scale = context.getResources().getDisplayMetrics().density;
        return (int) (dipValue * scale + 0.5f);
    }

    public void stopAndGoBack() {
        if (mGlobalVar.getIsFloatServiceRunning()) {
            Intent intent = new Intent();
            intent.setAction("com.opd.soeghtool.floatview");
            intent.putExtra("Visibility", "Show");
            sendBroadcast(intent);
        } else {
            Intent intent = new Intent(ButtonSettingService.this, FloatMenuService.class);
            startService(intent);
        }
        bIsNeedCloseMenu = false;
        stopSelf();
    }

    public View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.layout_button_setting_back:
                    if (bIsChanged) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(getBaseContext());
                        builder.setTitle(getResources().getString(R.string.string_pop_reminder))
                                .setMessage(getResources().getString(R.string.string_pop_button_setting_exit_reminder))
                                .setPositiveButton(getResources().getString(R.string.string_pop_button_setting_exit_save), new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        layout_button_setting_save.performClick();
                                        stopAndGoBack();
                                    }
                                })
                                .setNegativeButton(getResources().getString(R.string.string_pop_button_setting_exit_not_save), new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        mGlobalVar.loadGameData_GP(mGlobalVar.curPkgName,mGlobalVar.curLabelName,mGlobalVar.coorTbl,mGlobalVar.attrTbl,mGlobalVar.attrEvTbl);
                                        stopAndGoBack();
                                    }
                                })
                                .setNeutralButton(getResources().getString(R.string.string_pop_cancel), new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {

                                    }
                                });
                        final AlertDialog dialog = builder.create();
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                            if (Settings.canDrawOverlays(ButtonSettingService.this))
                                dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
                        } else {
                            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                        }
                        dialog.show();
                    } else {
                        stopAndGoBack();
                    }
                    break;
                case R.id.layout_button_setting_visible:
                    if (bIsShow) {
                        bIsShow = false;
                        iv_btn_setting_float_visible.setImageResource(R.drawable.visible);
                        tv_btn_setting_float_visible.setText(getResources().getString(R.string.string_float_menu_visible));
                        windowManager.removeView(button_setting_layout);
                        if (bIsDrawViewOn) {
                            windowManager.removeView(myDrawView);
                            bIsDrawViewOn = false;
                        }
                        paramsFloat.width = dip2px(ButtonSettingService.this, 75);
                        windowManager.updateViewLayout(btnFloatLayout, paramsFloat);
                    } else {
                        bIsShow = true;
                        iv_btn_setting_float_visible.setImageResource(R.drawable.invisible);
                        tv_btn_setting_float_visible.setText(getResources().getString(R.string.string_float_menu_hide));
                        windowManager.removeView(btnFloatLayout);
                        if (!mGlobalVar.getIsAdvSetNeedGuide()) {
                            if (!bIsDrawViewOn) {
                                windowManager.addView(myDrawView, paramsDraw);
                                bIsDrawViewOn = true;
                            }
                        }
                        windowManager.addView(button_setting_layout, paramsButtonSetting);
                        paramsFloat.width = dip2px(ButtonSettingService.this, 155);
                        windowManager.updateViewLayout(btnFloatLayout, paramsFloat);
                        //windowManager.updateViewLayout(btnFloatLayout,paramsFloat);
                        windowManager.addView(btnFloatLayout,paramsFloat);
                        //layout_btn_view.setVisibility(View.VISIBLE);
                    }
                    break;
                case R.id.layout_button_setting_reset:
                    AlertDialog.Builder builder = new AlertDialog.Builder(getBaseContext());
                    builder.setTitle(getResources().getString(R.string.string_pop_reminder))
                            .setMessage(getResources().getString(R.string.string_pop_button_setting_reset_confirm))
                            .setPositiveButton(getResources().getString(R.string.string_pop_confirm), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    int x, y;
                                    if (mIconSizeBig != 0) {
                                        iv_btn_setting_ring.setVisibility(View.GONE);
                                        mBtnEditFlag = 0;
                                        mIconSizeBig = 0;
                                    }

                                    if(Transfer_Con.ENABLE_GAME_DATA_IN_PHONE_GP)
                                    {
                                        iv_btn_setting_ring.setVisibility(View.GONE);
                                        mBtnEditFlag = 0;
                                        for(int a=0;a<mGlobalVar.getDeviceMaxButton();a++)
                                        {
                                            pttbl_temp[2*a]=mGlobalVar.coorTbl[2*a];
                                            pttbl_temp[2*a+1]=mGlobalVar.coorTbl[2*a+1];
                                        }

                                        for (int k = 0; k < 4; k++)
                                        {
                                            for(int a=0;a<mGlobalVar.getDeviceMaxButton();a++)
                                            {
                                                combo_pttbl_temp[k][2*a]=mGlobalVar.coorTbl[(mGlobalVar.getDeviceMaxButton()*(k+1)+a)*2] ;
                                                combo_pttbl_temp[k][2*a+1]=mGlobalVar.coorTbl[(mGlobalVar.getDeviceMaxButton()*(k+1)+a)*2+1];
                                            }
                                        }
                                        mGlobalVar.sendCoordinateToDevice_GP(true);
                                    }
                                    else {
                                        if (mGlobalVar.getmCurGame() >= Transfer_Con.MAX_GP_FIX_GAME_NUM) {
                                            mGlobalVar.loadCoordinateTable(mGlobalVar.getmCurPhone(), mGlobalVar.getmCurGame());
                                            pttbl_temp = mGlobalVar.getPTTable();
                                        } else {
                                            mGlobalVar.tranSet_Value(Transfer_Con.HID_CMD_CLR_POINT_TBL, mGlobalVar.getmCurPhone(), mGlobalVar.getmCurGame());
                                            if (mGlobalVar.get_CurPtTbl((byte) (mGlobalVar.getDeviceMaxButton() * 2), (byte) 0, u8DataBuffer)) {
                                                short a;
                                                //String str="";
                                                for (a = 0; a < mGlobalVar.getDeviceMaxButton(); a++) {
                                                    pttbl_temp[a] = (int) (u8DataBuffer[2 * a + 1] & 0xff) << 8;
                                                    pttbl_temp[a] += (int) (u8DataBuffer[2 * a] & 0xff);
                                                    //str+=String.valueOf(ptTbl[a])+", ";
                                                }
                                                //Log.d(TAG,str);
                                                if (mGlobalVar.get_CurPtTbl((byte) (mGlobalVar.getDeviceMaxButton() * 2), (byte) 1, u8DataBuffer)) {
                                                    //str="";
                                                    for (a = 0; a < mGlobalVar.getDeviceMaxButton(); a++) {
                                                        pttbl_temp[mGlobalVar.getDeviceMaxButton() + a] = (int) (u8DataBuffer[2 * a + 1] & 0xff) << 8;
                                                        pttbl_temp[mGlobalVar.getDeviceMaxButton() + a] += (int) (u8DataBuffer[2 * a] & 0xff);
                                                        //str+=String.valueOf(ptTbl[mGlobalVar.getDeviceMaxButton()+a])+", ";
                                                    }
                                                    mGlobalVar.setPtTbl(pttbl_temp);
                                                    //Log.d(TAG,str);
                                                }
                                            }
                                        }
                                    }
                                    TypedArray ar;
                                    if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)
                                        ar = getResources().obtainTypedArray(R.array.gm1_button_images);
                                    else
                                        ar = getResources().obtainTypedArray(R.array.hn1_button_images);
                                    for (int a = 0; a < ar.length(); a++) {
                                        iv_normal_btn[a].setVisibility(View.GONE);
                                        //if((a==Transfer_Con.TI_BUTTON_L_ROCKER)||(a==Transfer_Con.TI_BUTTON_R_ROCKER)||(a==Transfer_Con.TI_BUTTON_SHIFT)||(a==Transfer_Con.TI_BUTTON_LOGO))
                                        //   continue;
                                        y = pttbl_temp[a * 2] * panelHeight / 0x7FFF;
                                        x = pttbl_temp[a * 2 + 1] * panelWidth / 0x7FFF;
                                        iv_normal_btn[a].setX(x - mImageHalfSize);
                                        iv_normal_btn[a].setY(y - mImageHalfSize);
                                        //Log.i(TAG, "iv ; " + String.valueOf(a) + ",l=" + String.valueOf(y) + ",t=" + String.valueOf(x));
                                        if ((pttbl_temp[a * 2] != 0x7fff) || (pttbl_temp[a * 2 + 1] != 0x7fff))
                                            iv_normal_btn[a].setVisibility(View.VISIBLE);
                                    }
                                    ar.recycle();
                                    for (int k = 0; k < 4; k++) {
                                        if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)
                                            ar = getResources().obtainTypedArray(R.array.gm1_button_combo_l1_images);
                                        else
                                            ar = getResources().obtainTypedArray(R.array.hn1_button_combo_l1_images);
                                        for (int a = 0; a < ar.length(); a++) {
                                            if (a == (Transfer_Con.TI_BUTTON_L1 + k))
                                                continue;
                                            combo_pttbl_temp[k][a * 2 + 1] = 0x7FFF;
                                            combo_pttbl_temp[k][a * 2] = 0x7FFF;
                                            iv_combo_btn[k][a].setVisibility(View.GONE);
                                        }
                                        ar.recycle();
                                    }
                                    tv_btn_set_add_rmv_nor.performClick();
                                    bIsChanged = false;
                                }
                            })
                            .setNegativeButton(getResources().getString(R.string.string_pop_cancel), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                }
                            });
                    final AlertDialog dialog = builder.create();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        if (Settings.canDrawOverlays(ButtonSettingService.this))
                            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
                    } else {
                        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                    }
                    dialog.show();
                    break;

                case R.id.layout_button_setting_save:
                    if(Transfer_Con.ENABLE_GAME_DATA_IN_PHONE_GP)
                    {
                        if(bIsChanged) {

                            for(int a=0;a<mGlobalVar.getDeviceMaxButton();a++)
                            {
                                mGlobalVar.coorTbl[2*a]=pttbl_temp[2*a];
                                mGlobalVar.coorTbl[2*a+1]=pttbl_temp[2*a+1];
                            }

                            for (int k = 0; k < 4; k++)
                            {
                                for(int a=0;a<mGlobalVar.getDeviceMaxButton();a++)
                                {
                                    mGlobalVar.coorTbl[(mGlobalVar.getDeviceMaxButton()*(k+1)+a)*2] = combo_pttbl_temp[k][2*a];
                                    mGlobalVar.coorTbl[(mGlobalVar.getDeviceMaxButton()*(k+1)+a)*2+1] = combo_pttbl_temp[k][2*a+1];
                                }
                            }

                            mGlobalVar.sendCoordinateToDevice_GP(true);
                            bIsChanged = false;
                        }
                        if(bIsSaveAttrTable)
                        {
                            for(int a=0;a<mGlobalVar.getDeviceMaxButton();a++)
                            {
                                for(int k=0;k<3;k++)
                                {
                                    mGlobalVar.attrTbl[a][k] =g_u8tAttrTable[a][k];
                                }
                            }
                            mGlobalVar.sendAttributeToDevice_GP(true);
                            bIsSaveAttrTable = false;
                        }
                        if(bIsSaveAutoEventTbl) {
                            for(int a=0;a<(g_u8AutoEventTblUsed&0xff);a++)
                            {
                                mGlobalVar.attrEvTbl[a] = g_u8tAutoEventTbl[a];
                            }
                            mGlobalVar.sendAttributeEventTableToDevice_GP(true);
                            bIsSaveAutoEventTbl = false;
                        }
                        mGlobalVar.saveGameData_GP(mGlobalVar.curPkgName, mGlobalVar.curLabelName, mGlobalVar.coorTbl, mGlobalVar.attrTbl, mGlobalVar.attrEvTbl);

                    }
                    else {

                        mGlobalVar.setPtTbl(pttbl_temp);
                        String str = "";
                        for (int a = 0; a < mGlobalVar.getDeviceMaxButton(); a++) {
                            u8DataBuffer[a * 2] = (byte) (pttbl_temp[a] & 0xff);
                            u8DataBuffer[a * 2 + 1] = (byte) (pttbl_temp[a] >> 8);
                            str += String.valueOf(u8DataBuffer[a * 2]) + " " + String.valueOf(u8DataBuffer[a * 2 + 1]) + ", ";
                        }
                        if (BuildConfig.DEBUG)
                            Log.d(TAG, str);
                        str = "";
                        if (BuildConfig.DEBUG)
                            Log.d(TAG, "pt0:" + String.valueOf(pttbl_temp[0]) + "byte:" + String.valueOf(u8DataBuffer[0]) + " " + String.valueOf(u8DataBuffer[1]));
                        if (mGlobalVar.set_CurPtTbl((byte) (mGlobalVar.getDeviceMaxButton() * 2), (byte) 0, u8DataBuffer)) {

                            for (int a = 0; a < mGlobalVar.getDeviceMaxButton(); a++) {
                                u8DataBuffer[a * 2] = (byte) (pttbl_temp[mGlobalVar.getDeviceMaxButton() + a] & 0xff);
                                u8DataBuffer[a * 2 + 1] = (byte) (pttbl_temp[mGlobalVar.getDeviceMaxButton() + a] >> 8);
                                str += String.valueOf(u8DataBuffer[a * 2]) + " " + String.valueOf(u8DataBuffer[a * 2 + 1]) + ", ";
                            }
                            if (BuildConfig.DEBUG)
                                Log.d(TAG, str);
                            if (BuildConfig.DEBUG)
                                Log.d(TAG, "pt0:" + String.valueOf(pttbl_temp[mGlobalVar.getDeviceMaxButton()]) + "byte:" + String.valueOf(u8DataBuffer[0]) + " " + String.valueOf(u8DataBuffer[1]));
                            if (mGlobalVar.set_CurPtTbl((byte) (mGlobalVar.getDeviceMaxButton() * 2), (byte) 1, u8DataBuffer)) {
                                if (mGlobalVar.tranSet_Value(Transfer_Con.HID_CMD_SAVE_POINT_TBL, mGlobalVar.getmCurPhone(), mGlobalVar.getmCurGame())) {
                                    Toast.makeText(ButtonSettingService.this, getResources().getString(R.string.string_pop_file_save_success), Toast.LENGTH_SHORT).show();
                                }
                            }
                        }

                        for (int k = 0; k < 4; k++) {
                            if ((g_u8tAttrTable[Transfer_Con.TI_BUTTON_L1 + k][0] & 0xC0) == 0xC0) {
                                for (int a = 0; a < mGlobalVar.getDeviceMaxButton(); a++) {
                                    u8DataBuffer[a * 2] = (byte) (combo_pttbl_temp[k][a] & 0xff);
                                    u8DataBuffer[a * 2 + 1] = (byte) (combo_pttbl_temp[k][a] >> 8);
                                }
                                if (mGlobalVar.tranSetComboTbl((byte) k, (byte) (mGlobalVar.getDeviceMaxButton() * 2), (byte) 0, u8DataBuffer)) {

                                    for (int a = 0; a < mGlobalVar.getDeviceMaxButton(); a++) {
                                        u8DataBuffer[a * 2] = (byte) (combo_pttbl_temp[k][mGlobalVar.getDeviceMaxButton() + a] & 0xff);
                                        u8DataBuffer[a * 2 + 1] = (byte) (combo_pttbl_temp[k][mGlobalVar.getDeviceMaxButton() + a] >> 8);
                                    }
                                    if (mGlobalVar.tranSetComboTbl((byte) k, (byte) (mGlobalVar.getDeviceMaxButton() * 2), (byte) 1, u8DataBuffer)) {
                                        if (mGlobalVar.tranSet_Value(Transfer_Con.HID_CMD_SAVE_COMBO_PTTBL, 10, k)) {
                                            mGlobalVar.setComboPtTbl((byte) k, combo_pttbl_temp[k]);
                                            //Toast.makeText(ButtonSettingService.this,"保存成功",Toast.LENGTH_SHORT).show();
                                        }
                                    }
                                }
                            }
                        }
                        mGlobalVar.saveCoordinateTable(mGlobalVar.getmCurPhone(), mGlobalVar.getmCurGame());
                    }
                    bIsChanged = false;
                    break;
                case R.id.btn_btn_setting_test:
                    if (bIsTestOn) {
                        bIsTestOn = false;
                        btn_btn_setting_test.setText(getResources().getString(R.string.string_btn_btn_setting_test));
                        btn_btn_setting_test.setBackgroundColor(getResources().getColor(R.color.colorBottomBlue));
                    } else {
                        if (bIsChanged) {
                            AlertDialog.Builder builder1 = new AlertDialog.Builder(ButtonSettingService.this);
                            builder1.setTitle(getResources().getString(R.string.string_pop_reminder))
                                    .setMessage(getResources().getString(R.string.string_pop_button_setting_exit_save))
                                    .setPositiveButton(getResources().getString(R.string.string_pop_button_setting_exit_save), new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            layout_button_setting_save.performClick();
                                            iv_btn_setting_ring.setVisibility(View.GONE);
                                            bIsTestOn = true;
                                            btn_btn_setting_test.setText(getResources().getString(R.string.string_btn_btn_setting_exit_test));
                                            btn_btn_setting_test.setBackgroundColor(getResources().getColor(R.color.colorButtonOrange));
                                        }
                                    })
                                    .setNegativeButton(getResources().getString(R.string.string_pop_button_setting_exit_not_save), new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            iv_btn_setting_ring.setVisibility(View.GONE);
                                            bIsTestOn = true;
                                            btn_btn_setting_test.setText(getResources().getString(R.string.string_btn_btn_setting_exit_test));
                                            btn_btn_setting_test.setBackgroundColor(getResources().getColor(R.color.colorButtonOrange));
                                        }
                                    })
                                    .setNegativeButton(getResources().getString(R.string.string_pop_cancel), new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {

                                        }
                                    });
                            final AlertDialog dialog1 = builder1.create();
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                if (Settings.canDrawOverlays(ButtonSettingService.this))
                                    dialog1.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
                            } else {
                                dialog1.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                            }
                            dialog1.show();
                        } else {
                            iv_btn_setting_ring.setVisibility(View.GONE);
                            bIsTestOn = true;
                            btn_btn_setting_test.setText(getResources().getString(R.string.string_btn_btn_setting_exit_test));
                            btn_btn_setting_test.setBackgroundColor(getResources().getColor(R.color.colorButtonOrange));
                        }
                    }
                    break;
                case R.id.btn_btn_setting_guide:
                    mGlobalVar.setIsEnterAdvGuide(true);
                    btn_btn_setting_guide.setVisibility(View.GONE);
                    if (bIsDrawViewOn) {
                        windowManager.removeView(myDrawView);
                        bIsDrawViewOn = false;
                    }
                    Intent intent = new Intent(ButtonSettingService.this, UserGuideService.class);
                    startService(intent);
                    break;
                case R.id.btn_btn_setting_advance_next:
                    if (mAdvSettingStep2Index == 0) {
                        if(mGlobalVar.getIsSupportNewMacro_GP())
                        {
                            if ((g_u8ActionTblLen&0xff) > 2) {
                                g_u8TempAutoEventTbl[g_u8ActionTblStar + g_u8ActionTblLen] = 10; // inv time
                                g_u8ActionTblLen++;
                            }
                        }
                        else {
                            if ((g_u8ActionTblLen&0xff) > 0) {
                                g_u8TempAutoEventTbl[g_u8ActionTblStar + g_u8ActionTblLen] = 10; // inv time
                                g_u8ActionTblLen++;
                            }
                        }
                        // Log.d(TAG,"Key: "+String.valueOf(g_u8EVKey));

                        g_u8TempAutoEventTbl[g_u8ActionTblStar + g_u8ActionTblLen] = (byte) (g_u8EVKey | 0x80);  // touch
                        g_u8ActionTblLen++;
                        g_u8TempAutoEventTbl[g_u8ActionTblStar + g_u8ActionTblLen] = 20; // inv time
                        g_u8ActionTblLen++;
                        g_u8TempAutoEventTbl[g_u8ActionTblStar + g_u8ActionTblLen] = (byte) (g_u8EVKey);   // touch release
                        g_u8ActionTblLen++;

                        String str1 = "";

                        if(mGlobalVar.getIsSupportNewMacro_GP())
                        {
                            for (int a = 2; a < (g_u8ActionTblLen&0xff); a += 4) {
                                if ((g_u8TempAutoEventTbl[g_u8ActionTblStar + a] & 0x20) == 0x20) {
                                    if ((g_u8TempAutoEventTbl[g_u8ActionTblStar + a] & 0x10) == 0x10) {
                                        str1 += "(R1+" + Transfer_Con.tButtonName[(g_u8TempAutoEventTbl[g_u8ActionTblStar + a] & 0x0F)] + getResources().getString(R.string.string_pop_button_setting_advance_event_click);
                                    } else {
                                        str1 += "(L1+" + Transfer_Con.tButtonName[(g_u8TempAutoEventTbl[g_u8ActionTblStar + a] & 0x0F)] + getResources().getString(R.string.string_pop_button_setting_advance_event_click);
                                    }
                                } else
                                    str1 += Transfer_Con.tButtonName[(g_u8TempAutoEventTbl[g_u8ActionTblStar + a] & 0x3F)] + getResources().getString(R.string.string_pop_button_setting_advance_event_click_1);
                            }
                        }
                        else {
                            for (int a = 0; a < (g_u8ActionTblLen&0xff); a += 4) {
                                if ((g_u8TempAutoEventTbl[g_u8ActionTblStar + a] & 0x20) == 0x20) {
                                    if ((g_u8TempAutoEventTbl[g_u8ActionTblStar + a] & 0x10) == 0x10) {
                                        str1 += "(R1+" + Transfer_Con.tButtonName[(g_u8TempAutoEventTbl[g_u8ActionTblStar + a] & 0x0F)] + getResources().getString(R.string.string_pop_button_setting_advance_event_click);
                                    } else {
                                        str1 += "(L1+" + Transfer_Con.tButtonName[(g_u8TempAutoEventTbl[g_u8ActionTblStar + a] & 0x0F)] + getResources().getString(R.string.string_pop_button_setting_advance_event_click);
                                    }
                                } else
                                    str1 += Transfer_Con.tButtonName[(g_u8TempAutoEventTbl[g_u8ActionTblStar + a] & 0x3F)] + getResources().getString(R.string.string_pop_button_setting_advance_event_click_1);
                            }
                        }
                        //str1+=Transfer_Con.tButtonName[(g_u8TempAutoEventTbl[g_u8ActionTblStar + g_u8ActionTblLen-2]&0x3F)]=" 点击";
                        tv_btn_setting_advance_msg.setText(getResources().getString(R.string.string_pop_button_setting_advance_macro) + str1);
                        mMacroBtnStep++;
                        if(mGlobalVar.getCurLanguageIndex()==2)
                            tv_btn_setting_advance_tip.setText(String.format("请选择第%d步按键", mMacroBtnStep));
                        else
                            tv_btn_setting_advance_tip.setText(String.format("Please select step %d button", mMacroBtnStep));
                    } else if (mAdvSettingStep2Index == 1) {
                        btnAdvEventShow();
                        if(mGlobalVar.getCurLanguageIndex()==2)
                            tv_btn_setting_advance_tip.setText(String.format("请选择%s按键事件", Transfer_Con.tButtonName[g_u8EVKey]));
                        else
                            tv_btn_setting_advance_tip.setText(String.format("Please select %s button event", Transfer_Con.tButtonName[g_u8EVKey]));
                    }
                    break;
                case R.id.btn_btn_setting_advance_confirm:
                    if (mAdvSettingStep2Index == 1) {
                        if (mBtnActionFlag != 0) {
                            Toast.makeText(ButtonSettingService.this, getResources().getString(R.string.string_pop_button_setting_advance_release), Toast.LENGTH_SHORT).show();
                            break;
                        }
                        g_u8ActionTblLen--;
                    }
                    layout_btn_setting_advance.setVisibility(View.GONE);
                    windowManager.addView(layout_advance_setting, paramsAdvance);
                    bIsAdvanceSettingOn = true;
                    if (mAdvSettingStep2Index == 0) {
                        if (mBtnEditRecordingFlag != 0) {
                            iv_btn_setting_ring.setVisibility(View.GONE);
                            mBtnEditRecordingFlag = 0;
                        }
                    } else if (mAdvSettingStep2Index == 1) {
                        if (mBtnEditRecordingFlag != 0) {
                            iv_btn_setting_ring.setVisibility(View.GONE);
                            mBtnEditRecordingFlag = 0;
                        }
                    }
                    tv_advance_setting_macro_btn_desc.setText(parseTempAutoEvent());
                    break;
                case R.id.iv_btn_setting_advance_zoom:
                    if (bIsSubViewOn) {
                        ViewGroup.LayoutParams adv_lp = layout_btn_setting_advance.getLayoutParams();
                        adv_lp.height = dip2px(ButtonSettingService.this, 30);
                        ll_layout_btn_setting_advance_sub.setVisibility(View.GONE);
                        iv_btn_setting_advance_zoom.setImageResource(R.drawable.zoom_up);
                        bIsSubViewOn = false;
                    } else {
                        ViewGroup.LayoutParams adv_lp = layout_btn_setting_advance.getLayoutParams();
                        adv_lp.height = panelHeight / 2;
                        ll_layout_btn_setting_advance_sub.setVisibility(View.VISIBLE);
                        iv_btn_setting_advance_zoom.setImageResource(R.drawable.zoom_down);
                        bIsSubViewOn = true;
                    }
                    break;
                default:
                    break;
            }
        }
    };

    @SuppressLint("ClickableViewAccessibility")
    void showFloatImage() {
        int x, y;
        //ViewGroup.LayoutParams para;

        if(Transfer_Con.ENABLE_GAME_DATA_IN_PHONE_GP)
        {
            System.arraycopy(mGlobalVar.coorTbl,0,pttbl_temp,0,mGlobalVar.getDeviceMaxButton() * 2);
        }
        else {
            pttbl_temp = mGlobalVar.getPTTable();
        }
        if(Transfer_Con.ENABLE_S2_MENU_COVER)
        {
            if(mGlobalVar.getIsForceS2Enable()) {
                S2_X = pttbl_temp[Transfer_Con.TI_BUTTON_S2 * 2 + 1];
                S2_Y = pttbl_temp[Transfer_Con.TI_BUTTON_S2 * 2];
                mGlobalVar.tranSet_Value(Transfer_Con.HID_CMD_SET_MENU_POS, 1, (S2_X << 16) | S2_Y);
            }
        }

        TypedArray ar;
        if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)
            ar = getResources().obtainTypedArray(R.array.gm1_button_images);
        else
            ar = getResources().obtainTypedArray(R.array.hn1_button_images);

        int len = ar.length();
        int[] resIds = new int[len];

        for(int a= 0;a<len;a++){
            final int k = a;
            boolean bShow = true;
            if(!bIsImageAlreadyCreate)
                iv_normal_btn[a] = new ImageView(ButtonSettingService.this);

            if(Transfer_Con.ENABLE_S2_QUICK_MENU&&!Transfer_Con.ENABLE_GN_LOGO_QUICK_MENU)
            {
                if(mGlobalVar.getIsSupportMenuKey()) {
                    if (a == Transfer_Con.TI_BUTTON_S2)
                        bShow=false;
                }
            }
            if(a == Transfer_Con.TI_BUTTON_L1) {
                if (mGlobalVar.getDeviceIndex() == Transfer_Con.DEVICE_GM1_INDEX) {
                    if (mGlobalVar.tranGet_Value((byte) (Transfer_Con.HID_CMD_GET_HW_SETTING), 0xFF, 0xFF, u8DataBuffer)) {
                        if ((u8DataBuffer[0] & 0x10) == 0x10)
                            bShow = false;
                    }
                }
            }

            resIds[a] = ar.getResourceId(a, 0);
            iv_normal_btn[a].setImageResource(resIds[a]);
            y = pttbl_temp[a * 2] * panelHeight / 0x7FFF;
            x = pttbl_temp[a * 2 + 1] * panelWidth / 0x7FFF;
            iv_normal_btn[a].setX(x - mImageHalfSize);
            iv_normal_btn[a].setY(y - mImageHalfSize);

            ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(mImageHalfSize*2,mImageHalfSize*2);
            iv_normal_btn[a].setAlpha(((float) mGlobalVar.getPt_Tbl_View_Alpha()) / 10);
            if((pttbl_temp[a*2]==0x7fff)&&(pttbl_temp[a*2+1]==0x7fff))
                bShow = false;

            if(bShow)
                iv_normal_btn[a].setVisibility(View.VISIBLE);
            else
                iv_normal_btn[a].setVisibility(View.GONE);

            if(!bIsImageAlreadyCreate)
            button_setting_layout.addView(iv_normal_btn[a],lp);

            final int index = a;
            iv_normal_btn[a].setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    {

                        if (!mGlobalVar.getIsAdvSetNeedGuide()) {
                            if (bIsDrawViewOn) {
                                if (bIsTestOn) {
                                    return;
                                }
                            }
                        }
                        if (bIsRecordMacro) {
                            iv_btn_setting_ring.setX(v.getX() - (mImgRingSize - mImageHalfSize));
                            iv_btn_setting_ring.setY(v.getY() - (mImgRingSize - mImageHalfSize));
                            if ((mMacroBtnStep > 10) && (mAdvSettingStep2Index == 0) || (mMacroBtnStep > 20)) {
                                Toast.makeText(ButtonSettingService.this, getResources().getString(R.string.string_pop_button_setting_advance_step_over), Toast.LENGTH_SHORT).show();
                            } else {
                                mBtnEditRecordingFlag = (index + 1);
                                g_u8EVKey = index;
                                btn_btn_setting_advance_next.performClick();
                            }
                        } else {
                            if ((mBtnEditFlag == (index + 1)) && (index < mGlobalVar.getDeviceLeftRockerIndex())) {
                                iv_btn_setting_ring.setVisibility(View.GONE);
                                TypedArray ar;
                                if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)
                                    ar = getResources().obtainTypedArray(R.array.gm1_button_images);
                                else
                                    ar = getResources().obtainTypedArray(R.array.hn1_button_images);
                                int resIds = ar.getResourceId(index, 0);
                                iv_advance_setting_btn.setImageResource(resIds);
                                windowManager.addView(layout_advance_setting, paramsAdvance);
                                bIsAdvanceSettingOn = true;
                                advanceSettingShow(index);
                                layout_button_setting_add_remove.setVisibility(View.GONE);
                                ar.recycle();
                            } else {
                                mBtnEditFlag = (index + 1);
                            }
                        }
                    }
                }
            });

            iv_normal_btn[a].setOnTouchListener(new View.OnTouchListener() {

                long[] hints = new long[2];
                int prevX = 0, prevY = 0;

                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    boolean bIsLongPress = false;
                    if (bIsRecordMacro) {
                        Log.d(TAG, "Recording");
                        return false;
                    }
                    if (!mGlobalVar.getIsAdvSetNeedGuide()) {
                        if (bIsDrawViewOn) {
                            if (bIsTestOn) {
                                myDrawView.onTouchEvent(event);
                                return false;
                            }
                        }
                    }
                    //if (SystemClock.uptimeMillis() - hints[0] >= 300)
                    //Log.d(TAG,String.valueOf(SystemClock.uptimeMillis() - hints[0]));

                    int pos_x, pos_y;
                    switch (event.getAction()) {
                        case MotionEvent.ACTION_DOWN:
                            System.arraycopy(hints, 1, hints, 0, hints.length - 1);
                            hints[hints.length - 1] = SystemClock.uptimeMillis();
                            prevX = (int) event.getRawX();
                            prevY = (int) event.getRawY();
                            iv_btn_setting_ring.setX(v.getX() - (mImgRingSize - mImageHalfSize));
                            iv_btn_setting_ring.setY(v.getY() - (mImgRingSize - mImageHalfSize));
                            iv_btn_setting_ring.setVisibility(View.VISIBLE);

                            break;
                        case MotionEvent.ACTION_MOVE:
                            if ((Math.abs(prevX - (int) event.getRawX()) > 10) || (Math.abs(prevY - (int) event.getRawY()) > 10)) {
                                bIsChanged = true;
                                pos_x = (int) event.getRawX() - mImageHalfSize;
                                pos_y = (int) event.getRawY() - mImageHalfSize;
                                v.setX(pos_x);
                                v.setY(pos_y);
                                pttbl_temp[2 * k] = (pos_y + mImageHalfSize) * 0x7FFF / panelHeight;
                                pttbl_temp[2 * k + 1] = (pos_x + mImageHalfSize) * 0x7FFF / panelWidth;
                                iv_btn_setting_ring.setX(v.getX() - (mImgRingSize - mImageHalfSize));
                                iv_btn_setting_ring.setY(v.getY() - (mImgRingSize - mImageHalfSize));
                                layout_button_setting_add_remove.setVisibility(View.GONE);
                                showNormalEmptyBtn(false);
                                iv_button_setting_remove.setVisibility(View.VISIBLE);
                            }
                            break;
                        case MotionEvent.ACTION_UP:
                            System.arraycopy(hints, 1, hints, 0, hints.length - 1);
                            hints[hints.length - 1] = SystemClock.uptimeMillis();
                            iv_btn_setting_ring.setX(v.getX() - (mImgRingSize - mImageHalfSize));
                            iv_btn_setting_ring.setY(v.getY() - (mImgRingSize - mImageHalfSize));


                            if (v.getX() > iv_button_setting_remove.getX() - iv_button_setting_remove.getWidth() / 2 && (v.getX() < (iv_button_setting_remove.getX() + iv_button_setting_remove.getWidth() / 2))
                                    && v.getY() > iv_button_setting_remove.getY() - iv_button_setting_remove.getHeight() / 2 && (v.getY() < (iv_button_setting_remove.getY() + iv_button_setting_remove.getHeight() / 2))
                            ) {
                                pttbl_temp[2 * k] = 0x7FFF;
                                pttbl_temp[2 * k + 1] = 0x7FFF;
                                v.setVisibility(View.GONE);
                                iv_btn_setting_ring.setVisibility(View.GONE);
                            }
                            layout_button_setting_add_remove.setVisibility(View.VISIBLE);
                            iv_button_setting_remove.setVisibility(View.GONE);
                            tv_btn_set_add_rmv_nor.performClick();
                            if (SystemClock.uptimeMillis() - hints[0] >= 300) {
                                bIsLongPress = true;
                                mBtnEditFlag = (index + 1);
                            }
                            break;
                    }
                    return bIsLongPress;
                }
            });
        }
        ar.recycle();

        for (int k = 0; k < 4; k++) {
            final int group = k;
            boolean bGroupShow = true,bIconShow=true;
            if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)
            {
                if (k == 1)
                    ar = getResources().obtainTypedArray(R.array.gm1_button_combo_r1_images);
                else if (k == 2)
                    ar = getResources().obtainTypedArray(R.array.gm1_button_combo_l2_images);
                else if (k == 3)
                    ar = getResources().obtainTypedArray(R.array.gm1_button_combo_r2_images);
                else //f(k==0)
                    ar = getResources().obtainTypedArray(R.array.gm1_button_combo_l1_images);
            }
            else {
                if (k == 1)
                    ar = getResources().obtainTypedArray(R.array.hn1_button_combo_r1_images);
                else if (k == 2)
                    ar = getResources().obtainTypedArray(R.array.hn1_button_combo_l2_images);
                else if (k == 3)
                    ar = getResources().obtainTypedArray(R.array.hn1_button_combo_r2_images);
                else //f(k==0)
                    ar = getResources().obtainTypedArray(R.array.hn1_button_combo_l1_images);
            }
            len = ar.length();
            resIds = new int[len];
            if ((g_u8tAttrTable[Transfer_Con.TI_BUTTON_L1 + k][0] & 0xC0) != 0xC0)
                bGroupShow = false;

            if(Transfer_Con.ENABLE_GAME_DATA_IN_PHONE_GP)
            {
                for (int a = 0; a < mGlobalVar.getDeviceMaxButton(); a++) {
                    combo_pttbl_temp[k][2*a] = mGlobalVar.coorTbl[((k+1)*mGlobalVar.getDeviceMaxButton()+a)*2];
                    combo_pttbl_temp[k][2*a+1] = mGlobalVar.coorTbl[((k+1)*mGlobalVar.getDeviceMaxButton()+a)*2+1];
                    //Log.d(TAG,String.format("22222222 k=%d,a=%d  x=%d,y=%d",k,a,combo_pttbl_temp[k][2*a],combo_pttbl_temp[k][2*a+1]));
                }
            }
            else {
                if (mGlobalVar.tranGetComboTbl((byte) k, (byte) (mGlobalVar.getDeviceMaxButton() * 2), (byte) 0, u8DataBuffer)) {
                    int a;
                    // String str="";
                    for (a = 0; a < mGlobalVar.getDeviceMaxButton(); a++) {
                        combo_pttbl_temp[k][a] = (int) (u8DataBuffer[2 * a + 1] & 0xff) << 8;
                        combo_pttbl_temp[k][a] += (int) (u8DataBuffer[2 * a] & 0xff);
                        // str+=String.valueOf(combo_pttbl_temp[k][a])+", ";
                    }
                    if (mGlobalVar.tranGetComboTbl((byte) k, (byte) (mGlobalVar.getDeviceMaxButton() * 2), (byte) 1, u8DataBuffer)) {
                        for (a = 0; a < mGlobalVar.getDeviceMaxButton(); a++) {
                            combo_pttbl_temp[k][mGlobalVar.getDeviceMaxButton() + a] = (int) (u8DataBuffer[2 * a + 1] & 0xff) << 8;
                            combo_pttbl_temp[k][mGlobalVar.getDeviceMaxButton() + a] += (int) (u8DataBuffer[2 * a] & 0xff);
                            // Log.d(TAG,"wwww "+String.valueOf(combo_pttbl_temp[k][mGlobalVar.getDeviceMaxButton() + a]));
                            // str+=String.valueOf(combo_pttbl_temp[k][mGlobalVar.getDeviceMaxButton() +a])+", ";
                            //Log.d(TAG,"w2 "+String.valueOf(combo_pttbl_temp[k][mGlobalVar.getDeviceMaxButton() + a]));
                        }
                        // Log.d(TAG,str);
                    }
                }
            }
                for (int a = 0; a < ar.length(); a++) {
                    final int index = a;
                    if((combo_pttbl_temp[k][a*2]==0x7fff)&&(combo_pttbl_temp[k][a*2+1]==0x7fff))
                        bIconShow = false;
                    else
                        bIconShow = true;
                    if (a == (Transfer_Con.TI_BUTTON_L1 + k))
                        bIconShow = false;
                    x = combo_pttbl_temp[k][a*2+1] * panelWidth / 0x7FFF;
                    y = combo_pttbl_temp[k][a*2] * panelHeight / 0x7FFF;
                    if(!bIsImageAlreadyCreate)
                    iv_combo_btn[k][a] = new ImageView(ButtonSettingService.this);

                    resIds[a] = ar.getResourceId(a, 0);
                    iv_combo_btn[k][a].setImageResource(resIds[a]);
                    iv_combo_btn[k][a].setX(x-mImageHalfSize);
                    iv_combo_btn[k][a].setY(y-mImageHalfSize);
                    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(mImageHalfSize*2,mImageHalfSize*2);
                    iv_combo_btn[k][a].setAlpha(((float) mGlobalVar.getPt_Tbl_View_Alpha()) / 10);
                    if(bIconShow&&bGroupShow)
                        iv_combo_btn[k][a].setVisibility(View.VISIBLE);
                    else
                        iv_combo_btn[k][a].setVisibility(View.GONE);
                    if(!bIsImageAlreadyCreate)
                    button_setting_layout.addView(iv_combo_btn[k][a],lp);
                    iv_combo_btn[k][a].setOnTouchListener(new View.OnTouchListener() {
                        int prevX = 0, prevY = 0;

                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            int pos_x, pos_y;

                            if (bIsRecordMacro) {
                                iv_btn_setting_ring.setX(v.getX() - (mImgRingSize - mImageHalfSize));
                                iv_btn_setting_ring.setY(v.getY() - (mImgRingSize - mImageHalfSize));
                                if ((mMacroBtnStep > 10) && (mAdvSettingStep2Index == 0) || (mMacroBtnStep > 20)) {
                                    Toast.makeText(ButtonSettingService.this, getResources().getString(R.string.string_pop_button_setting_advance_step_over), Toast.LENGTH_SHORT).show();
                                } else {
                                    mBtnEditRecordingFlag = (index + 1) | group << 4;
                                    g_u8EVKey = 0x20 | (group << 4) | index;
                                    btn_btn_setting_advance_next.performClick();
                                }
                                return false;
                            }
                            if (!mGlobalVar.getIsAdvSetNeedGuide()) {
                                if (bIsDrawViewOn) {
                                    if (bIsTestOn) {
                                        myDrawView.onTouchEvent(event);
                                        return true;
                                    }
                                }
                            }
                            switch (event.getAction()) {
                                case MotionEvent.ACTION_DOWN:
                                    prevX = (int) event.getRawX();
                                    prevY = (int) event.getRawY();
                                    iv_btn_setting_ring.setX(v.getX() - (mImgRingSize - mImageHalfSize));
                                    iv_btn_setting_ring.setY(v.getY() - (mImgRingSize - mImageHalfSize));
                                    iv_btn_setting_ring.setVisibility(View.VISIBLE);
                                    break;
                                case MotionEvent.ACTION_MOVE:
                                    if ((Math.abs(prevX - (int) event.getRawX()) > 10) || (Math.abs(prevY - (int) event.getRawY()) > 10)) {
                                        bIsChanged = true;
                                        pos_x = (int) event.getRawX() - mImageHalfSize;
                                        pos_y = (int) event.getRawY() - mImageHalfSize;
                                        v.setX(pos_x);
                                        v.setY(pos_y);
                                        combo_pttbl_temp[group][2 * index] = (pos_y + mImageHalfSize) * 0x7FFF / panelHeight;
                                        combo_pttbl_temp[group][2 * index + 1] = (pos_x + mImageHalfSize) * 0x7FFF / panelWidth;
                                        iv_btn_setting_ring.setX(v.getX() - (mImgRingSize - mImageHalfSize));
                                        iv_btn_setting_ring.setY(v.getY() - (mImgRingSize - mImageHalfSize));
                                        showComboEmptyBtn(false);
                                        layout_button_setting_add_remove.setVisibility(View.GONE);
                                        iv_button_setting_remove.setVisibility(View.VISIBLE);
                                    }
                                    break;
                                case MotionEvent.ACTION_UP:
                                    iv_btn_setting_ring.setX(v.getX() - (mImgRingSize - mImageHalfSize));
                                    iv_btn_setting_ring.setY(v.getY() - (mImgRingSize - mImageHalfSize));
                                    if (v.getX() > iv_button_setting_remove.getX() - iv_button_setting_remove.getWidth() / 2 && (v.getX() < (iv_button_setting_remove.getX() + iv_button_setting_remove.getWidth() / 2))
                                            && v.getY() > iv_button_setting_remove.getY() - iv_button_setting_remove.getHeight() / 2 && (v.getY() < (iv_button_setting_remove.getY() + iv_button_setting_remove.getHeight() / 2))
                                    ) {
                                        combo_pttbl_temp[group][2 * index] = 0x7FFF;
                                        combo_pttbl_temp[group][2 * index + 1] = 0x7FFF;
                                        v.setVisibility(View.GONE);
                                        iv_btn_setting_ring.setVisibility(View.GONE);
                                    }
                                    layout_button_setting_add_remove.setVisibility(View.VISIBLE);
                                    iv_button_setting_remove.setVisibility(View.GONE);
                                    tv_btn_set_add_rmv_combo.performClick();
                                    break;
                            }
                            return true;
                        }
                    });
                }
            ar.recycle();
        }
        bIsImageAlreadyCreate =  true;
    /*
        for(int k=0;k<4;k++) {

            String str="group="+String.valueOf(k)+" :";
            for (int a = 0; a < mGlobalVar.getDeviceMaxButton()*2; a++) {
                str+=String.valueOf(combo_pttbl_temp[k][a])+", ";
            }
            Log.d(TAG,str);
        }
    */
    }

    LinearLayout layout_btn_set_add_rmv_combo;
    TextView tv_btn_set_add_rmv_nor, tv_btn_set_add_rmv_combo;
    MyGridView gv_btn_set_add_rmv_nor, gv_btn_set_add_rmv_combo;
    ScrollView sv_btn_set_add_rmv_combo, sv_btn_set_add_rmv_nor;
    int start_x=0, start_y=0;

    void showNormalEmptyBtn(boolean show) {
        byte u8counter = 0;
        TypedArray ar;
        if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)
            ar = getResources().obtainTypedArray(R.array.gm1_button_images);
        else
            ar = getResources().obtainTypedArray(R.array.hn1_button_images);

        for (int a = 0; a < ar.length(); a++) {
            if ((pttbl_temp[a * 2] == 0x7fff) && (pttbl_temp[a * 2 + 1] == 0x7fff)) {
                if (show) {
                    iv_normal_btn[a].setX(start_x + (u8counter % 7) * mImageHalfSize * 2);
                    iv_normal_btn[a].setY(start_y + u8counter / 7 * mImageHalfSize * 2);
                    if(Transfer_Con.ENABLE_S2_QUICK_MENU&&!Transfer_Con.ENABLE_GN_LOGO_QUICK_MENU)
                    {
                        if(mGlobalVar.getIsSupportMenuKey()) {
                            if (a == Transfer_Con.TI_BUTTON_S2)
                                continue;
                        }
                    }
                    iv_normal_btn[a].setVisibility(View.VISIBLE);
                    u8counter++;
                } else {
                    iv_normal_btn[a].setVisibility(View.GONE);
                }
            }
        }
        ar.recycle();
    }

    void hideAllComboBtn(boolean val) {
        TypedArray ar;
        if (val) {
            for (int k = 0; k < 4; k++) {
                if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)
                    ar = getResources().obtainTypedArray(R.array.gm1_button_combo_l1_images);
                else
                    ar = getResources().obtainTypedArray(R.array.hn1_button_combo_l1_images);
                if ((g_u8tAttrTable[Transfer_Con.TI_BUTTON_L1 + k][0] & 0xC0) == 0xC0) {
                    for (int a = 0; a < ar.length(); a++) {
                        if (a == (Transfer_Con.TI_BUTTON_L1 + k))
                            continue;
                        iv_combo_btn[k][a].setVisibility(View.GONE);
                    }
                }
                ar.recycle();
            }
        } else {
            for (int k = 0; k < 4; k++) {
                if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)
                    ar = getResources().obtainTypedArray(R.array.gm1_button_combo_l1_images);
                else
                    ar = getResources().obtainTypedArray(R.array.hn1_button_combo_l1_images);
                if ((g_u8tAttrTable[Transfer_Con.TI_BUTTON_L1 + k][0] & 0xC0) == 0xC0) {
                    for (int a = 0; a < ar.length(); a++) {
                        if (a == (Transfer_Con.TI_BUTTON_L1 + k))
                            continue;
                        if(Transfer_Con.ENABLE_S2_QUICK_MENU&&!Transfer_Con.ENABLE_GN_LOGO_QUICK_MENU)
                        {
                            if(mGlobalVar.getIsSupportMenuKey()) {
                                if (a == Transfer_Con.TI_BUTTON_S2)
                                    continue;
                            }
                        }
                        if ((combo_pttbl_temp[k][a * 2] != 0x7fff) || (combo_pttbl_temp[k][a * 2 + 1] != 0x7fff))
                            iv_combo_btn[k][a].setVisibility(View.VISIBLE);
                    }
                }
                ar.recycle();
            }
        }
    }

    void showComboEmptyBtn(boolean show) {
        byte u8counter = 0;
        TypedArray ar;
        for (int k = 0; k < 4; k++) {
            if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)
                ar = getResources().obtainTypedArray(R.array.gm1_button_combo_l1_images);
            else
                ar = getResources().obtainTypedArray(R.array.hn1_button_combo_l1_images);
            if ((g_u8tAttrTable[Transfer_Con.TI_BUTTON_L1 + k][0] & 0xC0) == 0xC0) {
                for (int a = 0; a < ar.length(); a++) {
                    if (a == (Transfer_Con.TI_BUTTON_L1 + k))
                        continue;
                    if (BuildConfig.DEBUG)
                        Log.d(TAG, String.format("group=%d,id=%d,x=%d,y=%d", k, a, combo_pttbl_temp[k][a * 2], combo_pttbl_temp[k][a * 2 + 1]));

                    if ((combo_pttbl_temp[k][a * 2] == 0x7fff) && (combo_pttbl_temp[k][a * 2 + 1] == 0x7fff)) {

                        if (show) {
                            iv_combo_btn[k][a].setX(start_x + (u8counter % 7) * mImageHalfSize * 2);
                            iv_combo_btn[k][a].setY(start_y + u8counter / 7 * mImageHalfSize * 2);
                            //Log.i(TAG,"iv ; "+String.valueOf(a)+",l="+String.valueOf(y)+",t="+String.valueOf(x));
                            if(Transfer_Con.ENABLE_S2_QUICK_MENU&&!Transfer_Con.ENABLE_GN_LOGO_QUICK_MENU)
                            {
                                if(mGlobalVar.getIsSupportMenuKey()) {
                                    if (a == Transfer_Con.TI_BUTTON_S2)
                                        continue;
                                }
                            }
                            iv_combo_btn[k][a].setVisibility(View.VISIBLE);
                            u8counter++;
                        } else {
                            iv_combo_btn[k][a].setVisibility(View.GONE);
                        }
                    }
                }
            }
            ar.recycle();
        }
        ViewGroup.LayoutParams lp = layout_button_setting_add_remove.getLayoutParams();
        //int height = dip2px(this, 130);
        if (lp.height < (dip2px(this, 40) + (u8counter / 7 + 1) * mImageHalfSize * 2)) {
            //ViewGroup.LayoutParams lp = layout_button_setting_add_remove.getLayoutParams();
            lp.height = (dip2px(this, 40) + (u8counter / 7 + 1) * mImageHalfSize * 2);
            //Log.d(TAG, "height1:" + String.valueOf(lp.height));
        }
    }


    void showAddandRemove() {
        //ViewGroup.LayoutParams lp = layout_button_setting_add_remove.getLayoutParams();
        layout_button_setting_add_remove.setX(panelWidth / 2 - dip2px(ButtonSettingService.this, 100));
        layout_button_setting_add_remove.setY(dip2px(ButtonSettingService.this, 60));

        start_x = (int) layout_button_setting_add_remove.getX();
        start_y = (int) layout_button_setting_add_remove.getY() + dip2px(ButtonSettingService.this, 40);

        Log.d(TAG, String.format("x=%d,y=%d", start_x, start_y));
        //lp.height = dip2px(ButtonSettingService.this,150);
        //lp.width = dip2px(ButtonSettingService.this,200);
        layout_btn_set_add_rmv_combo = (LinearLayout) button_setting_layout.findViewById(R.id.layout_btn_set_add_rmv_combo);
        tv_btn_set_add_rmv_nor = (TextView) button_setting_layout.findViewById(R.id.tv_btn_set_add_rmv_nor);
        tv_btn_set_add_rmv_combo = (TextView) button_setting_layout.findViewById(R.id.tv_btn_set_add_rmv_combo);
        gv_btn_set_add_rmv_nor = (MyGridView) button_setting_layout.findViewById(R.id.gv_btn_set_add_rmv_nor);
        gv_btn_set_add_rmv_combo = (MyGridView) button_setting_layout.findViewById(R.id.gv_btn_set_add_rmv_combo);
        sv_btn_set_add_rmv_nor = (ScrollView) button_setting_layout.findViewById(R.id.sv_btn_set_add_rmv_nor);
        sv_btn_set_add_rmv_combo = (ScrollView) button_setting_layout.findViewById(R.id.sv_btn_set_add_rmv_combo);

        tv_btn_set_add_rmv_nor.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                sv_btn_set_add_rmv_nor.setVisibility(View.VISIBLE);
                sv_btn_set_add_rmv_combo.setVisibility(View.GONE);
                tv_btn_set_add_rmv_nor.setBackgroundColor(getResources().getColor(R.color.colorTextOrange));
                tv_btn_set_add_rmv_combo.setBackgroundColor(Color.rgb(192, 192, 192));
                //norAdapter.notifyDataSetChanged();
                showNormalEmptyBtn(true);
                showComboEmptyBtn(false);
            }
        });
        tv_btn_set_add_rmv_combo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sv_btn_set_add_rmv_nor.setVisibility(View.GONE);
                sv_btn_set_add_rmv_combo.setVisibility(View.VISIBLE);
                tv_btn_set_add_rmv_combo.setBackgroundColor(getResources().getColor(R.color.colorTextOrange));
                tv_btn_set_add_rmv_nor.setBackgroundColor(Color.rgb(192, 192, 192));
                showNormalEmptyBtn(false);
                showComboEmptyBtn(true);
                //comboAdapter.notifyDataSetChanged();
            }
        });
        showNormalEmptyBtn(true);
    }

    void showAdvSetNorContinue()
    {
        if((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.bContinueClick)
        {
            int delta = (int) (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF)] & 0xFF)*10;
            sb_advance_setting_continue_inv.setProgress(delta);
            String str = String.valueOf(delta) + " " +getResources().getString(R.string.string_input_pop_delay_ms);
            tv_advance_setting_continue_inv.setText(str);
            rb_adv_set_nor_combo_off.setChecked(true);
        }
    }

    void showAdvSetNorCombo() {
        if ((g_u8TempAttrTable[0] & (Transfer_Con.ATTR_COMBO_KEY | Transfer_Con.ATTR_AEV_ENABLE)) == (Transfer_Con.ATTR_COMBO_KEY | Transfer_Con.ATTR_AEV_ENABLE)) {
            rb_adv_set_nor_combo_on.setChecked(true);
        }
        else
            {
            rb_adv_set_nor_combo_off.setChecked(true);
        }
    }

    void showAdvSetMOBALink() {
        if(Transfer_Con.ENABLE_S2_QUICK_MENU||Transfer_Con.ENABLE_GN_LOGO_QUICK_MENU)
        {
            if(mGlobalVar.getIsSupportMenuKey()) {
                ckb_adv_set_moba_dir_flip.setVisibility(View.VISIBLE);
            }
        }
        if ((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.bSkillWithDirect) {
            if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF)] & 0x80) == 0x80) {
                ckb_adv_set_moba_dir_left.setChecked(true);
                ckb_adv_set_moba_dir_right.setChecked(false);
            }
            if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF)] & 0x40) == 0x40) {
                ckb_adv_set_moba_dir_right.setChecked(true);
                ckb_adv_set_moba_dir_left.setChecked(false);
            }

            if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF)] & 0x08) == 0x08)
            {
                ckb_adv_set_moba_dir_flip.setChecked(true);
            }
            else
            {
                ckb_adv_set_moba_dir_flip.setChecked(false);
            }
        } else {
            ckb_adv_set_moba_dir_right.setChecked(false);
            ckb_adv_set_moba_dir_left.setChecked(true);
        }
    }

    void showAdvSetMOBARange() {
        if ((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.bFullRangeClick)
        {
            int range = g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF)]+(g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF)+1]<<8);
            int delta = g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF)+2]+(g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF)+3]<<8);
            sb_advance_setting_moba_range.setProgress(range);
            sb_advance_setting_moba_range_delta.setProgress(delta);
        }
        else
        {
            sb_advance_setting_moba_range.setProgress(sb_advance_setting_moba_range.getMax()/4);
            sb_advance_setting_moba_range_delta.setProgress(sb_advance_setting_moba_range_delta.getMax()/2);
        }
        iv_btn_adv_range_bg.setVisibility(View.VISIBLE);
    }

    void showAdvSetFPSPull() {
        if ((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.bFPSPullGunDown) {
            int delta;
            delta = (int) (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + 4] & 0x0F);
            delta = delta * 256 + (int) (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + 2] & 0xFF);
            sb_advance_setting_fps_start.setProgress(g_u8tAutoEventTbl[g_u8TempAttrTable[1] & 0xFF] & 0xFF);
            sb_advance_setting_fps_inv.setProgress(g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + 1] & 0xFF);
            sb_advance_setting_fps_delta.setProgress((delta * panelHeight + 0x7FFF / 2) / 0x7FFF);
        } else {
            sb_advance_setting_fps_start.setProgress(20);
            sb_advance_setting_fps_inv.setProgress(10);
            sb_advance_setting_fps_delta.setProgress(2);
        }
    }

    String parseAutoEvent()   //连招
    {
        String str = "";
        if ((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO) {
            if (g_u8tAutoEventTbl[g_u8TempAttrTable[1] & 0xFF] == (byte) 0xFF)
                return str;
            str = getResources().getString(R.string.string_pop_button_setting_advance_macro);
            for (int a = 0; a < (g_u8TempAttrTable[2] & 0xFF); a += 2) {
                if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x80) == 0x80) {
                    if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x20) == 0x20) {
                        if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x10) == 0x10) {
                            str += "(R1" + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down);
                        } else {
                            str += "(L1" + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down);
                        }
                    } else
                        str += Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x3F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down_1);
                } else if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x40) == 0x40) {
                    if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x20) == 0x20) {
                        if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x10) == 0x10) {
                            str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + ")";
                        } else {
                            str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + ")";
                        }
                    } else
                        str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x3F];
                } else {
                    if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x20) == 0x20) {
                        if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x10) == 0x10) {
                            str += "(R1" + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up);
                        } else {
                            str += "(L1" + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up);
                        }
                    } else
                        str += Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x3F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up_1);
                }
                if (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] == (byte) 0xFF) {
                    break;
                }
                if (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] == 0) {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_same_time);
                } else {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_wait) + String.valueOf((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xFF) * 10) + "ms, ";
                }
            }
            str += "。";
        }
        else if ((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO_NEW) {
            if (g_u8tAutoEventTbl[g_u8TempAttrTable[1] & 0xFF] == (byte) 0xFF)
                return str;
            str = getResources().getString(R.string.string_pop_button_setting_advance_macro);
            for (int a = 2; a < (g_u8TempAttrTable[2] & 0xFF); a += 2) {
                if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x80) == 0x80) {
                    if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x20) == 0x20) {
                        if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x10) == 0x10) {
                            str += "(R1" + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down);
                        } else {
                            str += "(L1" + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down);
                        }
                    } else
                        str += Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x3F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down_1);
                } else if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x40) == 0x40) {
                    if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x20) == 0x20) {
                        if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x10) == 0x10) {
                            str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + ")";
                        } else {
                            str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + ")";
                        }
                    } else
                        str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x3F];
                } else {
                    if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x20) == 0x20) {
                        if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x10) == 0x10) {
                            str += "(R1" + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up);
                        } else {
                            str += "(L1" + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up);
                        }
                    } else
                        str += Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x3F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up_1);
                }
                if (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] == (byte) 0xFF) {
                    break;
                }
                if (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] == 0) {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_same_time);
                } else {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_wait) + String.valueOf((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xFF) * 10) + "ms, ";
                }
            }
            str += "。";
        }

        return str;
    }

    String parseTempAutoEvent()   //连招
    {
        String str = "";
        str = getResources().getString(R.string.string_pop_button_setting_advance_macro);
        if(mGlobalVar.getIsSupportNewMacro_GP())
        {
            for (int a = 2; a < (g_u8ActionTblLen&0xff); a += 2) {
                if ((g_u8TempAutoEventTbl[a] & 0x80) == 0x80) {
                    if (((g_u8TempAutoEventTbl[a] & 0x20) == 0x20)) {
                        if ((g_u8TempAutoEventTbl[a] & 0x10) == 0x10) {
                            str += "(R1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down);
                        } else {
                            str += "(L1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down);
                        }
                    } else
                        str += Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x3F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down_1);
                } else if ((g_u8TempAutoEventTbl[a] & 0x40) == 0x40) {
                    if (((g_u8TempAutoEventTbl[a] & 0x20) == 0x20)) {
                        if ((g_u8TempAutoEventTbl[a] & 0x10) == 0x10) {
                            str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + "(R1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + ")";
                        } else {
                            str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + "(L1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + ")";
                        }
                    } else
                        str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x3F];
                } else {
                    if (((g_u8TempAutoEventTbl[a] & 0x20) == 0x20)) {
                        if ((g_u8TempAutoEventTbl[a] & 0x10) == 0x10) {
                            str += "(R1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up);
                        } else {
                            str += "(L1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up);
                        }
                    } else
                        str += Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x3F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up_1);
                }
                if (g_u8TempAutoEventTbl[a + 1] == (byte) 0xFF) {
                    break;
                }
                if (g_u8TempAutoEventTbl[a + 1] == 0) {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_same_time);
                } else {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_wait) + String.valueOf((g_u8TempAutoEventTbl[a + 1] & 0xff) * 10) + "ms, ";
                }
            }
        }
        else {
            for (int a = 0; a < (g_u8ActionTblLen&0xff); a += 2) {
                if ((g_u8TempAutoEventTbl[a] & 0x80) == 0x80) {
                    if (((g_u8TempAutoEventTbl[a] & 0x20) == 0x20)) {
                        if ((g_u8TempAutoEventTbl[a] & 0x10) == 0x10) {
                            str += "(R1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down);
                        } else {
                            str += "(L1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down);
                        }
                    } else
                        str += Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x3F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down_1);
                } else if ((g_u8TempAutoEventTbl[a] & 0x40) == 0x40) {
                    if (((g_u8TempAutoEventTbl[a] & 0x20) == 0x20)) {
                        if ((g_u8TempAutoEventTbl[a] & 0x10) == 0x10) {
                            str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + "(R1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + ")";
                        } else {
                            str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + "(L1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + ")";
                        }
                    } else
                        str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x3F];
                } else {
                    if (((g_u8TempAutoEventTbl[a] & 0x20) == 0x20)) {
                        if ((g_u8TempAutoEventTbl[a] & 0x10) == 0x10) {
                            str += "(R1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up);
                        } else {
                            str += "(L1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up);
                        }
                    } else
                        str += Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x3F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up_1);
                }
                if (g_u8TempAutoEventTbl[a + 1] == (byte) 0xFF) {
                    break;
                }
                if (g_u8TempAutoEventTbl[a + 1] == 0) {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_same_time);
                } else {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_wait) + String.valueOf((g_u8TempAutoEventTbl[a + 1] & 0xff) * 10) + "ms, ";
                }
            }
        }
        return str;
    }

    String parseVirtualEvent()   //连招
    {
        String str = "";
        if ((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO_ADV) {
            if (g_u8tAutoEventTbl[g_u8TempAttrTable[1] & 0xFF] == (byte) 0xFF)
                return str;
            str = getResources().getString(R.string.string_pop_button_setting_advance_macro);
            for (int a = 0; a < (g_u8TempAttrTable[2] & 0xFF); a += 5) {
                if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x80) == 0x80) {
                    int x = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xff);
                    int y = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 2] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 3] & 0xff);

                    x = (x * panelHeight +0x3FFF)/ 0x7FFF;
                    y = (y * panelWidth +0x3FFF)/ 0x7FFF;
                    if(mGlobalVar.getCurLanguageIndex()==1)
                        str += String.format("Coordinate(%d,%d)Press", y, x);
                        else
                        str += String.format("坐标(%d,%d)按下", y, x);
                } else if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 2] & 0x80) == 0x80) {
                    int x = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xff);
                    int y = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 2] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 3] & 0xff);

                    x = (x * panelHeight +0x3FFF)/ 0x7FFF;
                    y = (y * panelWidth +0x3FFF)/ 0x7FFF;
                    if(mGlobalVar.getCurLanguageIndex()==1)
                        str += String.format("swipe to coordinate(%d,%d)", y, x);
                    else
                        str += String.format("滑至坐标(%d,%d)", y, x);

                } else {
                    int x = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xff);
                    int y = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 2] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 3] & 0xff);

                    x = (x * panelHeight +0x3FFF)/ 0x7FFF;
                    y = (y * panelWidth +0x3FFF)/ 0x7FFF;
                    if(mGlobalVar.getCurLanguageIndex()==1)
                        str += String.format("coordinate(%d,%d)Release", y, x);
                    else
                        str += String.format("坐标(%d,%d)松开", y, x);
                }
                if (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 4] == (byte) 0xFF) {
                    break;
                }
                if (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 4] == 0) {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_same_time);
                } else {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_wait) + String.valueOf((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 4] & 0xFF) * 10) + "ms, ";
                }
            }
            str += "。";
        }
        else if ((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO_ADV_NEW) {
            if (g_u8tAutoEventTbl[g_u8TempAttrTable[1] & 0xFF] == (byte) 0xFF)
                return str;
            str = getResources().getString(R.string.string_pop_button_setting_advance_macro);
            for (int a = 2; a < (g_u8TempAttrTable[2] & 0xFF); a += 5) {
                if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x80) == 0x80) {
                    int x = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xff);
                    int y = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 2] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 3] & 0xff);

                    x = (x * panelHeight +0x3FFF)/ 0x7FFF;
                    y = (y * panelWidth +0x3FFF)/ 0x7FFF;
                    if(mGlobalVar.getCurLanguageIndex()==1)
                        str += String.format("Coordinate(%d,%d)Press", y, x);
                    else
                        str += String.format("坐标(%d,%d)按下", y, x);
                } else if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 2] & 0x80) == 0x80) {
                    int x = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xff);
                    int y = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 2] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 3] & 0xff);

                    x = (x * panelHeight +0x3FFF)/ 0x7FFF;
                    y = (y * panelWidth +0x3FFF)/ 0x7FFF;
                    if(mGlobalVar.getCurLanguageIndex()==1)
                        str += String.format("swipe to coordinate(%d,%d)", y, x);
                    else
                        str += String.format("滑至坐标(%d,%d)", y, x);

                } else {
                    int x = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xff);
                    int y = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 2] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 3] & 0xff);

                    x = (x * panelHeight +0x3FFF)/ 0x7FFF;
                    y = (y * panelWidth +0x3FFF)/ 0x7FFF;
                    if(mGlobalVar.getCurLanguageIndex()==1)
                        str += String.format("coordinate(%d,%d)Release", y, x);
                    else
                        str += String.format("坐标(%d,%d)松开", y, x);
                }
                if (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 4] == (byte) 0xFF) {
                    break;
                }
                if (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 4] == 0) {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_same_time);
                } else {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_wait) + String.valueOf((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 4] & 0xFF) * 10) + "ms, ";
                }
            }
            str += "。";
        }
        return str;
    }


    void showAdvSetMacroQuick() {
        if(mGlobalVar.getIsSupportNewMacro_GP())
        {
            rg_btn_advance_setting_macro_toggle.setVisibility(View.VISIBLE);
        }
        else
        {
            rg_btn_advance_setting_macro_toggle.setVisibility(View.GONE);
        }
       // Toast.makeText(ButtonSettingService.this,String.format("att=%d,%d,%d,  ev=%d,%d,%d",g_u8TempAttrTable[0],g_u8TempAttrTable[1],g_u8TempAttrTable[2],g_u8tAutoEventTbl[g_u8TempAttrTable[1]&0xFF],g_u8tAutoEventTbl[(g_u8TempAttrTable[1]&0xFF)+1],g_u8tAutoEventTbl[(g_u8TempAttrTable[1]&0xFF)+2]),Toast.LENGTH_SHORT).show();
        if ((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO_NEW) {
            if ((g_u8tAutoEventTbl[g_u8TempAttrTable[1] & 0xFF] & 0x80) == 0x80)
                rb_btn_advance_setting_macro_up.setChecked(true);
            else if ((g_u8tAutoEventTbl[g_u8TempAttrTable[1] & 0xFF] & 0x40) == 0x40)
                rb_btn_advance_setting_macro_loop.setChecked(true);
            else
                rb_btn_advance_setting_macro_down.setChecked(true);
        }
        else
            rb_btn_advance_setting_macro_down.setChecked(true);
        tv_advance_setting_macro_btn_desc.setText(parseAutoEvent());
    }

    void showAdvSetVirtual() {
        if(mGlobalVar.getIsSupportNewMacro_GP())
        {
            rg_advance_setting_macro_virtual.setVisibility(View.VISIBLE);
        }
        else
        {
            rg_advance_setting_macro_virtual.setVisibility(View.GONE);
        }

        if ((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO_ADV_NEW) {
        if((g_u8tAutoEventTbl[g_u8TempAttrTable[1]&0xFF]&0x80)==0x80)
            rb_advance_setting_macro_virtual_up.setChecked(true);
        else if((g_u8tAutoEventTbl[g_u8TempAttrTable[1]&0xFF]&0x40)==0x40)
            rb_advance_setting_macro_virtual_loop.setChecked(true);
        else
            rb_advance_setting_macro_virtual_down.setChecked(true);
        }
        else
            rb_advance_setting_macro_virtual_down.setChecked(true);
        tv_layout_advance_setting_macro_virtual_desc.setText(parseVirtualEvent());
        if (Transfer_Con.ENABLE_VIRTUAL_MACRO)
            btn_advance_setting_macro_virtual_set.setVisibility(View.VISIBLE);
    }

    void showAdvSetSwipe() {
        int distance = 100;
        float r = 1;
        if ((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.bSwipe) {
            long x, y, x1, y1;

            y = (pttbl_temp[g_u8ButtonID * 2] * panelHeight + 0x3FFF) / 0x7FFF;
            x = (pttbl_temp[g_u8ButtonID * 2 + 1] * panelWidth + 0x3FFF) / 0x7FFF;

            y1 = g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + 1] & 0xFF;
            y1 = (y1 << 8) + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + 2] & 0xFF);

            y1 = (y1 * panelHeight + 0x3FFF) / 0x7FFF;

            x1 = g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + 3] & 0xFF;
            x1 = (x1 << 8) + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + 4] & 0xFF);
            x1 = (x1 * panelWidth + 0x3FFF) / 0x7FFF;

            Log.d(TAG, String.format("sta x=%d,y=%d, end x=%d,y=%d", x, y, x1, y1));
            if (Math.abs(y1 - y) < 5)    // =
            {
                if (x1 > x) {
                    rb_advance_setting_swipe_right.setChecked(true);
                    distance = (int) (x1 - x);
                } else if (x1 < x) {
                    rb_advance_setting_swipe_left.setChecked(true);
                    distance = (int) (x - x1);
                }
            } else if (y1 > y) {
                if (Math.abs(x1 - x) < 5) //=
                {
                    rb_advance_setting_swipe_down.setChecked(true);
                } else if (x1 > x) {
                    rb_advance_setting_swipe_rd.setChecked(true);
                    r = 1.414f;
                } else if (x1 < x) {
                    rb_advance_setting_swipe_ld.setChecked(true);
                    r = 1.414f;
                }
                distance = (int) (y1 - y);
            } else //if(y1<y)
            {
                if (Math.abs(x1 - x) < 5)    // =
                {
                    rb_advance_setting_swipe_up.setChecked(true);
                } else if (x1 > x) {
                    rb_advance_setting_swipe_ru.setChecked(true);
                    r = 1.414f;
                } else if (x1 < x) {
                    rb_advance_setting_swipe_lu.setChecked(true);
                    r = 1.414f;
                }
                distance = (int) (y - y1);
            }

        }

        Log.d(TAG, String.format("distance=%d", (int) (distance * r)));

        sb_advance_setting_swipe_sub.setProgress((int) (distance * r));
    }

    void btnSelectShow() {
        //layout_btn_setting_list_btn = (LinearLayout) button_setting_layout.findViewById(R.id.layout_btn_setting_list_btn);
        layout_btn_setting_advance.setVisibility(View.VISIBLE);
        layout_btn_setting_adv_func_btn_action.setVisibility(View.GONE);
        //gv_btn_setting_btn_list = (GridView) button_setting_layout.findViewById(R.id.gv_btn_setting_btn_list);
    }

    void btnAdvEventShow() {
        if(mGlobalVar.getIsSupportNewMacro_GP())
        {
            if (g_u8ActionTblLen == 2) {
                rb_btn_setting_combine_press.setVisibility(View.VISIBLE);
                rb_btn_setting_combine_release.setVisibility(View.GONE);
                rb_btn_setting_combine_swipe.setVisibility(View.GONE);
                rb_btn_setting_combine_same.setVisibility(View.GONE);
            } else if ((g_u8ActionTblLen&0xff) < 6) {
                rb_btn_setting_combine_swipe.setVisibility(View.VISIBLE);
                rb_btn_setting_combine_same.setVisibility(View.VISIBLE);
            }

            if ((mBtnActionFlag & (1L << g_u8EVKey)) == 0) {
                rb_btn_setting_combine_press.setVisibility(View.VISIBLE);
                rb_btn_setting_combine_release.setVisibility(View.GONE);
            } else {
                rb_btn_setting_combine_press.setVisibility(View.GONE);
                rb_btn_setting_combine_release.setVisibility(View.VISIBLE);
            }
            layout_btn_setting_adv_func_btn_action.setVisibility(View.VISIBLE);
        }
        else
        {
            if (g_u8ActionTblLen == 0) {
                rb_btn_setting_combine_press.setVisibility(View.VISIBLE);
                rb_btn_setting_combine_release.setVisibility(View.GONE);
                rb_btn_setting_combine_swipe.setVisibility(View.GONE);
                rb_btn_setting_combine_same.setVisibility(View.GONE);
            } else if (g_u8ActionTblLen < 4) {
                rb_btn_setting_combine_swipe.setVisibility(View.VISIBLE);
                rb_btn_setting_combine_same.setVisibility(View.VISIBLE);
            }

            if ((mBtnActionFlag & (1L << g_u8EVKey)) == 0) {
                rb_btn_setting_combine_press.setVisibility(View.VISIBLE);
                rb_btn_setting_combine_release.setVisibility(View.GONE);
            } else {
                rb_btn_setting_combine_press.setVisibility(View.GONE);
                rb_btn_setting_combine_release.setVisibility(View.VISIBLE);
            }
            layout_btn_setting_adv_func_btn_action.setVisibility(View.VISIBLE);
        }

    }

    void btnDelayShow() {
        AlertDialog.Builder builder = new AlertDialog.Builder(ButtonSettingService.this);
        //EditText input = new EditText(ButtonSettingService.this);

        View view = LayoutInflater.from(ButtonSettingService.this).inflate(R.layout.pop_delay_input_layout, null, false);
        final EditText input = (EditText) view.findViewById(R.id.input_pop_delay_layout);
        builder.setView(view);
        builder.setTitle(getResources().getString(R.string.string_pop_button_setting_advance_event_inv_time))
                .setMessage(getResources().getString(R.string.string_pop_button_setting_advance_event_inv_time_keyin))
                .setPositiveButton(getResources().getString(R.string.string_pop_confirm), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        int delay = 200;
                        if (!android.text.TextUtils.isEmpty(input.getText())) {
                            delay = Integer.parseInt(input.getText().toString());
                            // Toast.makeText(ButtonSettingService.this, "输入: " + String.valueOf(delay), Toast.LENGTH_SHORT).show();
                        }
                        mMacroBtnStep++;
                        layout_btn_setting_adv_func_btn_action.setVisibility(View.GONE);
                        if (mu8BtnAction == 1) {
                            g_u8TempAutoEventTbl[g_u8ActionTblLen&0xff] = (byte) (0x80 | g_u8EVKey);
                            g_u8ActionTblLen++;
                            rb_btn_setting_combine_press.setChecked(false);
                        } else if (mu8BtnAction == 2) {
                            g_u8TempAutoEventTbl[g_u8ActionTblLen&0xff] = (byte) (g_u8EVKey);
                            g_u8ActionTblLen++;
                            rb_btn_setting_combine_release.setChecked(false);
                        } else if (mu8BtnAction == 3) {
                            g_u8TempAutoEventTbl[g_u8ActionTblLen&0xff] = (byte) (0x40 | g_u8EVKey);
                            g_u8ActionTblLen++;
                            rb_btn_setting_combine_swipe.setChecked(false);
                        } else if (mu8BtnAction == 4) {
                            g_u8ActionTblLen--;
                            g_u8TempAutoEventTbl[g_u8ActionTblLen&0xff] = 0;
                            g_u8ActionTblLen++;
                            if ((g_u8TempAutoEventTbl[(g_u8ActionTblLen&0xff) - 2] & 0x80) == 0) {
                                g_u8TempAutoEventTbl[g_u8ActionTblLen&0xff] = (byte) (g_u8EVKey);
                                mBtnActionFlag &= ~(1L << g_u8EVKey);
                            } else {
                                g_u8TempAutoEventTbl[g_u8ActionTblLen&0xff] = (byte) (0x80 | g_u8EVKey);
                                mBtnActionFlag |= 1L << g_u8EVKey;
                            }
                            g_u8ActionTblLen++;
                            rb_btn_setting_combine_same.setChecked(false);
                        }
                        g_u8TempAutoEventTbl[g_u8ActionTblLen&0xff] = (byte) ((delay + 5) / 10);
                        g_u8ActionTblLen++;
                        tv_btn_setting_advance_msg.setText(parseTempAutoEvent());
                        if(mGlobalVar.getCurLanguageIndex()==1)
                            tv_btn_setting_advance_tip.setText(String.format("Please select the button at step %d", mMacroBtnStep / 2 + 1));
                        else
                            tv_btn_setting_advance_tip.setText(String.format("请选择第%d步按键", mMacroBtnStep / 2 + 1));
                    }
                });
        final AlertDialog dialog = builder.create();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (Settings.canDrawOverlays(ButtonSettingService.this))
                dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        } else {
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        }
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
    }

    LinearLayout layout_advance_setting_fps_pull, layout_advance_setting_moba_dir, layout_advance_setting_swipe_sub,layout_advance_setting_moba_range;
    LinearLayout layout_advance_setting_normal_single, layout_advance_setting_nor_combo, layout_advance_setting_normal_continue, layout_advance_setting_moba_cancel, layout_advance_setting_macro_btn, layout_advance_setting_macro_virtual;
    Button btn_advance_setting_macro_btn_set, btn_advance_setting_macro_btn_import, btn_advance_setting_macro_btn_save, btn_advance_setting_quick_import_save, btn_advance_setting_quick_import_load, btn_advance_setting_quick_import_recommend;
    SeekBar sb_advance_setting_fps_start, sb_advance_setting_fps_inv, sb_advance_setting_fps_delta, sb_advance_setting_swipe_sub,sb_advance_setting_continue_inv,sb_advance_setting_moba_range,sb_advance_setting_moba_range_delta;
    CheckBox ckb_adv_set_moba_dir_left, ckb_adv_set_moba_dir_right,ckb_adv_set_moba_dir_flip;
    TextView tv_advance_setting_macro_btn_desc, tv_advance_setting_swipe_sub, tv_layout_advance_setting_macro_virtual_desc,tv_advance_setting_continue_inv,tv_advance_setting_fps_inv, tv_advance_setting_fps_delta,tv_advance_setting_moba_range,tv_advance_setting_moba_range_delta;
    RadioButton rb_adv_set_nor_combo_off, rb_adv_set_nor_combo_on, rb_btn_setting_combine_press, rb_btn_setting_combine_release, rb_btn_setting_combine_swipe, rb_btn_setting_combine_same;
    RadioButton rb_btn_advance_setting_macro_down,rb_btn_advance_setting_macro_up,rb_btn_advance_setting_macro_loop,rb_advance_setting_macro_virtual_down,rb_advance_setting_macro_virtual_up,rb_advance_setting_macro_virtual_loop;
    ImageView iv_advance_setting_fps_start_del, iv_advance_setting_fps_start_add, iv_advance_setting_fps_inv_del, iv_advance_setting_fps_inv_add, iv_advance_setting_fps_delta_del, iv_advance_setting_fps_delta_add;
    RadioGroup rg_btn_advance_setting_macro_toggle,rg_advance_setting_macro_virtual;
    // Virtual Macro(User Combine)
    ScrollView  sv_usercombin_bg_list;
    LinearLayout ll_usercombin_toolbar;
    ImageView iv_usercombin_bg, iv_usercombin_toolbar_pos;
    Button btn_usercombin_change_bg, btn_usercombin_change_reset, btn_usercombin_change_finish,btn_usercombin_bg_back,btn_usercombin_bg_alpha,btn_button_setting_macro_edit_cancel,btn_button_setting_macro_edit_confirm;
    MyGridView  gv_bg_iv_list;
    void advanceSettingInitial() {
        //Title
        iv_advance_setting_btn = (ImageView) layout_advance_setting.findViewById(R.id.iv_advance_setting_btn);
        tv_advance_setting_title = (TextView) layout_advance_setting.findViewById(R.id.tv_advance_setting_title);
        btn_advance_setting_cancel = (Button) layout_advance_setting.findViewById(R.id.btn_advance_setting_cancel);
        btn_advance_setting_confirm = (Button) layout_advance_setting.findViewById(R.id.btn_advance_setting_confirm);
        //Step 1
        rb_advance_setting_normal = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_normal);
        rb_advance_setting_fps = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_fps);
        rb_advance_setting_moba = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_moba);
        rb_advance_setting_swipe = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_swipe);
        rb_advance_setting_macro = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_macro);
        rb_advance_setting_quick_import = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_quick_import);
        //Step 2
        // normal
        layout_advance_setting_normal = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_normal);
        rb_advance_setting_nor_single = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_nor_single);
        rb_advance_setting_nor_combo = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_nor_combo);
        rb_advance_setting_nor_continue = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_nor_continue);

        if((mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_HN1_INDEX)||(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_HN2_INDEX)) {
            if(mGlobalVar.get_IntVersion()>=((1<<24)+(1<<8)+18))
                rb_advance_setting_nor_continue.setVisibility(View.VISIBLE);
        }
        else if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX) {
            if(mGlobalVar.get_IntVersion()>=((1<<24)+(1<<8)+18))
                rb_advance_setting_nor_continue.setVisibility(View.VISIBLE);
        }
        //FPS
        layout_advance_setting_fps = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_fps);
        rb_advance_setting_fps_pull = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_fps_pull);
        //MOBA
        layout_advance_setting_moba = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_moba);
        rb_advance_setting_moba_link = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_moba_link);
        rb_advance_setting_moba_range = layout_advance_setting.findViewById(R.id.rb_advance_setting_moba_range);
        rb_advance_setting_moba_cancel = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_moba_cancel);
        if((mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_HN1_INDEX)||(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_HN2_INDEX)||(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)) {
            if(mGlobalVar.get_IntVersion()>=((1<<24)+(1<<8)+20))
                rb_advance_setting_moba_range.setVisibility(View.VISIBLE);
        }
        //Swipe
        layout_advance_setting_swipe = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_swipe);
        rb_advance_setting_swipe_up = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_swipe_up);
        rb_advance_setting_swipe_down = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_swipe_down);
        rb_advance_setting_swipe_left = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_swipe_left);
        rb_advance_setting_swipe_right = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_swipe_right);
        rb_advance_setting_swipe_lu = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_swipe_lu);
        rb_advance_setting_swipe_ld = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_swipe_ld);
        rb_advance_setting_swipe_ru = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_swipe_ru);
        rb_advance_setting_swipe_rd = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_swipe_rd);
        //Macro
        layout_advance_setting_macro = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_macro);
        rb_advance_setting_macro_btn_quick = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_macro_btn_quick);
        rb_advance_setting_macro_btn_adv = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_macro_btn_adv);
        rb_advance_setting_macro_virtual = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_macro_virtual);
        rb_btn_advance_setting_macro_down = (RadioButton) layout_advance_setting.findViewById(R.id.rb_btn_advance_setting_macro_down);
        rb_btn_advance_setting_macro_up = (RadioButton) layout_advance_setting.findViewById(R.id.rb_btn_advance_setting_macro_up);
        rb_btn_advance_setting_macro_loop = (RadioButton) layout_advance_setting.findViewById(R.id.rb_btn_advance_setting_macro_loop);
        rg_btn_advance_setting_macro_toggle = layout_advance_setting.findViewById(R.id.rg_btn_advance_setting_macro_toggle);
        rg_advance_setting_macro_virtual = layout_advance_setting.findViewById(R.id.rg_advance_setting_macro_virtual);
        rb_advance_setting_macro_virtual_down = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_macro_virtual_down);
        rb_advance_setting_macro_virtual_up = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_macro_virtual_up);
        rb_advance_setting_macro_virtual_loop = (RadioButton) layout_advance_setting.findViewById(R.id.rb_advance_setting_macro_virtual_loop);
        // save load
        layout_advance_setting_quick_import = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_quick_import);
        // Step3
        layout_advance_setting_fps_pull = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_fps_pull);
        layout_advance_setting_moba_dir = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_moba_dir);
        layout_advance_setting_moba_range = layout_advance_setting.findViewById(R.id.layout_advance_setting_moba_range);
        layout_advance_setting_normal_single = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_normal_single);
        layout_advance_setting_normal_continue = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_normal_continue);
        layout_advance_setting_nor_combo = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_nor_combo);
        layout_advance_setting_moba_cancel = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_moba_cancel);
        layout_advance_setting_swipe_sub = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_swipe_sub);
        layout_advance_setting_macro_btn = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_macro_btn);
        layout_advance_setting_macro_virtual = (LinearLayout) layout_advance_setting.findViewById(R.id.layout_advance_setting_macro_virtual);

        // Step4
        btn_advance_setting_macro_btn_set = layout_advance_setting.findViewById(R.id.btn_advance_setting_macro_btn_set);
        btn_advance_setting_macro_btn_edit  = layout_advance_setting.findViewById(R.id.btn_advance_setting_macro_btn_edit);
        btn_advance_setting_macro_btn_import = layout_advance_setting.findViewById(R.id.btn_advance_setting_macro_btn_import);
        btn_advance_setting_macro_btn_save = layout_advance_setting.findViewById(R.id.btn_advance_setting_macro_btn_save);
        tv_advance_setting_macro_btn_desc = (TextView) layout_advance_setting.findViewById(R.id.tv_advance_setting_macro_btn_desc);
        tv_btn_setting_advance_detail = (TextView) layout_advance_setting.findViewById(R.id.tv_advance_setting_detail);
        tv_layout_advance_setting_macro_virtual_desc = (TextView) layout_advance_setting.findViewById(R.id.tv_layout_advance_setting_macro_virtual_desc);
        btn_advance_setting_macro_virtual_set = layout_advance_setting.findViewById(R.id.btn_advance_setting_macro_virtual_set);
        btn_advance_setting_macro_virtual_edit = layout_advance_setting.findViewById(R.id.btn_advance_setting_macro_virtual_edit);
        // continue click
        sb_advance_setting_continue_inv = layout_advance_setting.findViewById(R.id.sb_advance_setting_continue_inv);
        tv_advance_setting_continue_inv = layout_advance_setting.findViewById(R.id.tv_advance_setting_continue_inv);

        sb_advance_setting_continue_inv.setMax(2000);
        sb_advance_setting_continue_inv.setProgress(0);
        String str = String.valueOf(0) + " " +getResources().getString(R.string.string_input_pop_delay_ms);
        tv_advance_setting_continue_inv.setText(str);
        sb_advance_setting_continue_inv.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                progress = progress/10*10;
                String str = String.valueOf(progress) + " " +getResources().getString(R.string.string_input_pop_delay_ms);
                tv_advance_setting_continue_inv.setText(str);
                sb_advance_setting_continue_inv.setProgress(progress);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        // Combo
        rb_adv_set_nor_combo_off = layout_advance_setting.findViewById(R.id.rb_adv_set_nor_combo_off);
        rb_adv_set_nor_combo_on = layout_advance_setting.findViewById(R.id.rb_adv_set_nor_combo_on);
        // MOBA

        ckb_adv_set_moba_dir_left = (CheckBox) layout_advance_setting.findViewById(R.id.ckb_adv_set_moba_dir_left);
        ckb_adv_set_moba_dir_right = (CheckBox) layout_advance_setting.findViewById(R.id.ckb_adv_set_moba_dir_right);
        ckb_adv_set_moba_dir_flip = (CheckBox) layout_advance_setting.findViewById(R.id.ckb_adv_set_moba_dir_flip);
        sb_advance_setting_moba_range = layout_advance_setting.findViewById(R.id.sb_advance_setting_moba_range);
        sb_advance_setting_moba_range_delta = layout_advance_setting.findViewById(R.id.sb_advance_setting_moba_range_delta);
        sb_advance_setting_moba_range.setMax(0x4000);
        sb_advance_setting_moba_range_delta.setMax(0x1000);
        tv_advance_setting_moba_range = layout_advance_setting.findViewById(R.id.tv_advance_setting_moba_range);
        tv_advance_setting_moba_range_delta = layout_advance_setting.findViewById(R.id.tv_advance_setting_moba_range_delta);
        iv_btn_adv_range_bg = layout_advance_setting.findViewById(R.id.iv_btn_adv_range_bg);
        // FPS
        sb_advance_setting_fps_start = (SeekBar) layout_advance_setting.findViewById(R.id.sb_advance_setting_fps_start);
        sb_advance_setting_fps_start.setMax(100);
        sb_advance_setting_fps_inv = (SeekBar) layout_advance_setting.findViewById(R.id.sb_advance_setting_fps_inv);
        sb_advance_setting_fps_inv.setMax(100);
        tv_advance_setting_fps_inv = layout_advance_setting.findViewById(R.id.tv_advance_setting_fps_inv);


        sb_advance_setting_fps_delta = (SeekBar) layout_advance_setting.findViewById(R.id.sb_advance_setting_fps_delta);
        sb_advance_setting_fps_delta.setMax(40);
        tv_advance_setting_fps_delta = layout_advance_setting.findViewById(R.id.tv_advance_setting_fps_delta);

        iv_advance_setting_fps_start_del = (ImageView) layout_advance_setting.findViewById(R.id.iv_advance_setting_fps_start_del);
        iv_advance_setting_fps_start_add = (ImageView) layout_advance_setting.findViewById(R.id.iv_advance_setting_fps_start_add);
        iv_advance_setting_fps_inv_del = (ImageView) layout_advance_setting.findViewById(R.id.iv_advance_setting_fps_inv_del);
        iv_advance_setting_fps_inv_add = (ImageView) layout_advance_setting.findViewById(R.id.iv_advance_setting_fps_inv_add);
        iv_advance_setting_fps_delta_del = (ImageView) layout_advance_setting.findViewById(R.id.iv_advance_setting_fps_delta_del);
        iv_advance_setting_fps_delta_add = (ImageView) layout_advance_setting.findViewById(R.id.iv_advance_setting_fps_delta_add);

        iv_advance_setting_fps_start_del.setOnClickListener(addAndDelOnClickListener);
        iv_advance_setting_fps_start_add.setOnClickListener(addAndDelOnClickListener);
        iv_advance_setting_fps_inv_del.setOnClickListener(addAndDelOnClickListener);
        iv_advance_setting_fps_inv_add.setOnClickListener(addAndDelOnClickListener);
        iv_advance_setting_fps_delta_del.setOnClickListener(addAndDelOnClickListener);
        iv_advance_setting_fps_delta_add.setOnClickListener(addAndDelOnClickListener);
        //Swipe

        tv_advance_setting_swipe_sub = (TextView) layout_advance_setting.findViewById(R.id.tv_advance_setting_swipe_sub);
        sb_advance_setting_swipe_sub = (SeekBar) layout_advance_setting.findViewById(R.id.sb_advance_setting_swipe_sub);
        sb_advance_setting_swipe_sub.setMax(1000);

        rb_btn_setting_combine_press = (RadioButton) button_setting_layout.findViewById(R.id.rb_btn_setting_combine_press);
        rb_btn_setting_combine_release = (RadioButton) button_setting_layout.findViewById(R.id.rb_btn_setting_combine_release);
        rb_btn_setting_combine_swipe = (RadioButton) button_setting_layout.findViewById(R.id.rb_btn_setting_combine_swipe);
        rb_btn_setting_combine_same = (RadioButton) button_setting_layout.findViewById(R.id.rb_btn_setting_combine_same);

        btn_advance_setting_quick_import_save = (Button) layout_advance_setting.findViewById(R.id.btn_advance_setting_quick_import_save);
        btn_advance_setting_quick_import_load = (Button) layout_advance_setting.findViewById(R.id.btn_advance_setting_quick_import_load);
        btn_advance_setting_quick_import_recommend = (Button) layout_advance_setting.findViewById(R.id.btn_advance_setting_quick_import_recommend);


        ll_usercombin_toolbar = usercombin_layout.findViewById(R.id.ll_usercombin_toolbar);
        iv_usercombin_bg = usercombin_layout.findViewById(R.id.iv_usercombin_bg);
        iv_usercombin_toolbar_pos = usercombin_layout.findViewById(R.id.iv_usercombin_toolbar_pos);
        btn_usercombin_change_bg = usercombin_layout.findViewById(R.id.btn_usercombin_change_bg);
        btn_usercombin_change_reset = usercombin_layout.findViewById(R.id.btn_usercombin_change_reset);
        btn_usercombin_change_finish = usercombin_layout.findViewById(R.id.btn_usercombin_change_finish);
        btn_usercombin_bg_back = usercombin_layout.findViewById(R.id.btn_usercombin_bg_back);
        btn_usercombin_bg_alpha = usercombin_layout.findViewById(R.id.btn_usercombin_bg_alpha);
        gv_bg_iv_list = usercombin_layout.findViewById(R.id.gv_bg_iv_list);
        sv_usercombin_bg_list = usercombin_layout.findViewById(R.id.sv_usercombin_bg_list);

        iv_button_setting_macro_virtual_bg = button_setting_macro_virtual_bg_layout.findViewById(R.id.iv_button_setting_macro_virtual_bg);

        lv_button_setting_macro_edit = layout_button_setting_macro_edit.findViewById(R.id.lv_button_setting_macro_edit);
        btn_button_setting_macro_edit_cancel = layout_button_setting_macro_edit.findViewById(R.id.btn_button_setting_macro_edit_cancel);
        btn_button_setting_macro_edit_confirm = layout_button_setting_macro_edit.findViewById(R.id.btn_button_setting_macro_edit_confirm);
        advanceSettingEvent();
        advanceSettingHideStep3();
    }

    public View.OnClickListener addAndDelOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int data;
            switch (v.getId()) {
                case R.id.iv_advance_setting_fps_start_del:
                    data = sb_advance_setting_fps_start.getProgress();
                    if (data > 0)
                        data--;
                    sb_advance_setting_fps_start.setProgress(data);
                    break;
                case R.id.iv_advance_setting_fps_start_add:
                    data = sb_advance_setting_fps_start.getProgress();
                    if (data < sb_advance_setting_fps_start.getMax())
                        data++;
                    sb_advance_setting_fps_start.setProgress(data);
                    break;
                case R.id.iv_advance_setting_fps_inv_del:
                    data = sb_advance_setting_fps_inv.getProgress();
                    if (data > 0)
                        data--;
                    sb_advance_setting_fps_inv.setProgress(data);
                    break;
                case R.id.iv_advance_setting_fps_inv_add:
                    data = sb_advance_setting_fps_inv.getProgress();
                    if (data < sb_advance_setting_fps_inv.getMax())
                        data++;
                    sb_advance_setting_fps_inv.setProgress(data);
                    break;
                case R.id.iv_advance_setting_fps_delta_del:
                    data = sb_advance_setting_fps_delta.getProgress();
                    if (data > 0)
                        data--;
                    sb_advance_setting_fps_delta.setProgress(data);
                    tv_advance_setting_fps_delta.setText(String.valueOf(data*100/40)+"%");
                    break;
                case R.id.iv_advance_setting_fps_delta_add:
                    data = sb_advance_setting_fps_delta.getProgress();
                    if (data < sb_advance_setting_fps_delta.getMax())
                        data++;
                    sb_advance_setting_fps_delta.setProgress(data);
                    tv_advance_setting_fps_delta.setText(String.valueOf(data*100/40)+"%");
                    break;
            }
        }
    };

    void advanceSettingShow(int id) {
        g_u8ButtonID = id;
        g_u8TempAttrTable[0] = g_u8tAttrTable[id][0];
        g_u8TempAttrTable[1] = g_u8tAttrTable[id][1];
        g_u8TempAttrTable[2] = g_u8tAttrTable[id][2];

        switch ((int) g_u8TempAttrTable[0] & 0x7F) {
            case (byte) Transfer_Con.bContinueClick:
                rb_advance_setting_normal.setChecked(true);
                rb_advance_setting_normal.performClick();
                rb_advance_setting_nor_continue.setChecked(true);
                rb_advance_setting_nor_continue.performClick();
                break;
            case Transfer_Con.bFullRangeClick:
                rb_advance_setting_moba.setChecked(true);
                rb_advance_setting_moba.performClick();
                rb_advance_setting_moba_range.setChecked(true);
                rb_advance_setting_moba_range.performClick();
                break;
            case Transfer_Con.bSkillWithDirect:
                rb_advance_setting_moba.setChecked(true);
                rb_advance_setting_moba.performClick();
                rb_advance_setting_moba_link.setChecked(true);
                rb_advance_setting_moba_link.performClick();
                break;
            case Transfer_Con.bFPSPullGunDown:
                rb_advance_setting_fps.setChecked(true);
                rb_advance_setting_fps.performClick();
                rb_advance_setting_fps_pull.setChecked(true);
                rb_advance_setting_fps_pull.performClick();
                break;
            case Transfer_Con.ATTR_MACRO_NEW:
            case Transfer_Con.ATTR_MACRO:
                rb_advance_setting_macro.setChecked(true);
                rb_advance_setting_macro.performClick();
                rb_advance_setting_macro_btn_quick.setChecked(true);
                rb_advance_setting_macro_btn_quick.performClick();
                break;
            case Transfer_Con.bWZRYCancelConjure:
                rb_advance_setting_moba.setChecked(true);
                rb_advance_setting_moba.performClick();
                rb_advance_setting_moba_cancel.setChecked(true);
                rb_advance_setting_moba_cancel.performClick();
                break;
            case Transfer_Con.bSwipe:
                rb_advance_setting_swipe.setChecked(true);
                rb_advance_setting_swipe.performClick();
                break;
            case Transfer_Con.ATTR_MACRO_ADV_NEW:
            case Transfer_Con.ATTR_MACRO_ADV:
                rb_advance_setting_macro.setChecked(true);
                rb_advance_setting_macro.performClick();
                rb_advance_setting_macro_virtual.setChecked(true);
                rb_advance_setting_macro_virtual.performClick();
                break;
            case (byte) Transfer_Con.bCancelAutoEvent:
                rb_advance_setting_moba.setChecked(true);
                rb_advance_setting_moba.performClick();
                rb_advance_setting_moba_cancel.setChecked(true);
                rb_advance_setting_moba_cancel.performClick();
                break;
            case Transfer_Con.ATTR_COMBO_KEY:
                rb_advance_setting_normal.setChecked(true);
                rb_advance_setting_normal.performClick();
                rb_advance_setting_nor_combo.setChecked(true);
                rb_advance_setting_nor_combo.performClick();
                break;
            default:
                rb_advance_setting_normal.setChecked(true);
                rb_advance_setting_normal.performClick();
                rb_advance_setting_nor_single.setChecked(true);
                rb_advance_setting_nor_single.performClick();
                break;
        }
    }

    @SuppressLint("ClickableViewAccessibility")
    void advanceSettingEvent() {
        btn_advance_setting_cancel.setOnClickListener(advanceOnClickListener);
        btn_advance_setting_confirm.setOnClickListener(advanceOnClickListener);
        //Step 1
        rb_advance_setting_normal.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_fps.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_moba.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_swipe.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_macro.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_quick_import.setOnClickListener(advanceOnClickListener);
        //Step 2
        // normal
        rb_advance_setting_nor_single.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_nor_combo.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_nor_continue.setOnClickListener(advanceOnClickListener);
        //FPS
        rb_advance_setting_fps_pull.setOnClickListener(advanceOnClickListener);
        //MOBA
        rb_advance_setting_moba_link.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_moba_range.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_moba_cancel.setOnClickListener(advanceOnClickListener);
        //Swipe
        rb_advance_setting_swipe_up.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_swipe_down.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_swipe_left.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_swipe_right.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_swipe_lu.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_swipe_ld.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_swipe_ru.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_swipe_rd.setOnClickListener(advanceOnClickListener);
        //Macro
        rb_advance_setting_macro_btn_quick.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_macro_btn_adv.setOnClickListener(advanceOnClickListener);
        rb_advance_setting_macro_virtual.setOnClickListener(advanceOnClickListener);


        // Step4
        // Step4
        btn_advance_setting_macro_btn_set.setOnClickListener(advanceOnClickListener);
        btn_advance_setting_macro_btn_import.setOnClickListener(advanceOnClickListener);
        btn_advance_setting_macro_btn_save.setOnClickListener(advanceOnClickListener);
        btn_advance_setting_macro_virtual_set.setOnClickListener(advanceOnClickListener);
        btn_advance_setting_macro_virtual_edit.setOnClickListener(advanceOnClickListener);
        btn_advance_setting_macro_btn_edit.setOnClickListener(advanceOnClickListener);

        rb_btn_setting_combine_press.setOnClickListener(advanceOnClickListener);
        rb_btn_setting_combine_release.setOnClickListener(advanceOnClickListener);
        rb_btn_setting_combine_swipe.setOnClickListener(advanceOnClickListener);
        rb_btn_setting_combine_same.setOnClickListener(advanceOnClickListener);

        btn_advance_setting_quick_import_save.setOnClickListener(advanceOnClickListener);
        btn_advance_setting_quick_import_load.setOnClickListener(advanceOnClickListener);
        btn_advance_setting_quick_import_recommend.setOnClickListener(advanceOnClickListener);

        iv_usercombin_toolbar_pos.setOnClickListener(advanceOnClickListener);
        btn_usercombin_change_bg.setOnClickListener(advanceOnClickListener);
        btn_usercombin_change_reset.setOnClickListener(advanceOnClickListener);
        btn_usercombin_change_finish.setOnClickListener(advanceOnClickListener);
        btn_usercombin_bg_back.setOnClickListener(advanceOnClickListener);
        btn_usercombin_bg_alpha.setOnClickListener(advanceOnClickListener);

        btn_button_setting_macro_edit_cancel.setOnClickListener(advanceOnClickListener);
        btn_button_setting_macro_edit_confirm.setOnClickListener(advanceOnClickListener);

        sb_advance_setting_fps_inv.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tv_advance_setting_fps_inv.setText(String.valueOf(progress)+"%");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });
        sb_advance_setting_fps_delta.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tv_advance_setting_fps_delta.setText(String.valueOf(progress*100/sb_advance_setting_fps_delta.getMax())+"%");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        sb_advance_setting_moba_range.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tv_advance_setting_moba_range.setText(String.valueOf(progress*100/sb_advance_setting_moba_range.getMax())+"%");
                ViewGroup.LayoutParams lp = iv_btn_adv_range_bg.getLayoutParams();
                lp.height = progress*panelHeight/0x4000;
                lp.width = lp.height;
                iv_btn_adv_range_bg.setY(((pttbl_temp[g_u8ButtonID * 2] * panelHeight + 0x3FFF) / 0x7FFF)-lp.height/2);
                if(myDrawView.bHasNotchScreen)
                    iv_btn_adv_range_bg.setX(((pttbl_temp[g_u8ButtonID * 2+1] * panelWidth + 0x3FFF) / 0x7FFF)-lp.height/2-100);
                else
                    iv_btn_adv_range_bg.setX(((pttbl_temp[g_u8ButtonID * 2+1] * panelWidth + 0x3FFF) / 0x7FFF)-lp.height/2);
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

        sb_advance_setting_moba_range_delta.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                tv_advance_setting_moba_range_delta.setText(String.valueOf(progress*100/sb_advance_setting_moba_range_delta.getMax())+"%");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });


        iv_usercombin_bg.setOnTouchListener(new View.OnTouchListener() {
            int prevX[]=new int[5],prevY[]=new int[5],action[]=new int[3];
            boolean bMultiFlag = false;
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                    int id;
                    switch (event.getAction()&0xff) {
                        case MotionEvent.ACTION_DOWN:
                        case MotionEvent.ACTION_POINTER_DOWN:
                            id = (event.getAction()&0xff00)>>8;
                            prevX[id] = (int) event.getX(id);
                            prevY[id] = (int) event.getY(id);
                            action[id] = event.getAction();

                            if(id>0)
                            {
                                bMultiFlag =  true;
                                action[0] |= 0x10000;
                                action[id] |= 0x10000;
                            }
                            //Log.d(TAG,"ACTION_DOWN1: x="+String.valueOf(prevX[id])+", y="+String.valueOf(prevY[id]));
                            //Log.d(TAG,String.format("ActionDown %d,x=%d,y=%d",id,prevX[id],prevY[id]));
                            break;
                        case MotionEvent.ACTION_MOVE:
                            break;
                        case MotionEvent.ACTION_UP:
                        case MotionEvent.ACTION_POINTER_UP:
                            id = (event.getAction()&0xff00)>>8;
                            if ((Math.abs(prevX[id] - (int) event.getX(id))<20) && (Math.abs(prevY[id] - (int) event.getY(id))<20)) {
                                //Log.d(TAG,"ACTION_UP: "+String.valueOf(event.getAction())+" x="+String.valueOf(prevX[id])+", y="+String.valueOf(prevY[id])+" id="+String.valueOf(id)+" count="+String.valueOf(event.getPointerCount()));
                                if(myDrawView.g_u8VirtualMacroLen<120) {
                                    myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen] = action[id];
                                    myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen + 1] = prevX[id];
                                    myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen + 2] = prevY[id];
                                    myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen + 3] = event.getAction();
                                    if(bMultiFlag)
                                    {
                                        myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen + 3] |= (event.getPointerCount()<<16);
                                        bMultiFlag =false;
                                    }
                                    myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen + 4] = prevX[id];
                                    myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen + 5] = prevY[id];
                                    myDrawView.g_u8VirtualMacroLen += 6;

                                    for(int a=id;a<event.getPointerCount()-1;a++)
                                    {
                                        action[a] = action[a+1];
                                        prevX[a] = prevX[a+1];
                                        prevY[a] = prevY[a+1];
                                    }
                                }
                                else
                                {
                                    Toast.makeText(ButtonSettingService.this,getResources().getString(R.string.string_pop_button_setting_advance_event_max_step),Toast.LENGTH_SHORT).show();
                                }
                            }
                            else
                            {
                                if(myDrawView.g_u8VirtualMacroLen<120) {
                                    myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen] = action[id];
                                    myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen + 1] = prevX[id];
                                    myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen + 2] = prevY[id];
                                    myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen + 3] = event.getAction();
                                    if(bMultiFlag)
                                    {
                                        myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen + 3] |= (event.getPointerCount()<<16);
                                        bMultiFlag =false;
                                    }
                                    myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen + 4] = (int) event.getX(id);
                                    myDrawView.g_u32VirtualMacroData[myDrawView.g_u8VirtualMacroLen + 5] = (int) event.getY(id);
                                    myDrawView.g_u8VirtualMacroLen += 6;
                                    for(int a=id;a<event.getPointerCount()-1;a++)
                                    {
                                        action[a] = action[a+1];
                                        prevX[a] = prevX[a+1];
                                        prevY[a] = prevY[a+1];
                                    }
                                }
                                else
                                {
                                    Toast.makeText(ButtonSettingService.this,getResources().getString(R.string.string_pop_button_setting_advance_event_max_step),Toast.LENGTH_SHORT).show();
                                }
                               // Log.d(TAG,"ACTION_Move UP: "+String.valueOf(event.getAction())+" x="+String.valueOf(event.getX(id))+", y="+String.valueOf(event.getY(id))+" id="+String.valueOf(id)+" count="+String.valueOf(event.getPointerCount()));
                            }
                            if(!myDrawView.g_bIsVirtualMacroMode)
                                myDrawView.g_bIsVirtualMacroMode = true;
                            myDrawView.externOnDraw();
                            break;
                    }
                    return true;
                }
        });
    }



    void reassignedAEVTbl() {
        byte[] u8Temp = new byte[Transfer_Con.MAX_AUTOEVENT_LENGTH];
        int u16StartAddr = 0;
        Log.d(TAG, "reassignedAEVTbl");
        for (int a = 0; a < mGlobalVar.getDeviceMaxButton(); a++) {
            if ((g_u8tAttrTable[a][0] & Transfer_Con.ATTR_MASK) != 0) // 非无效
            {
                Log.d(TAG, "move");
                //转移到暂存队列
                System.arraycopy(g_u8tAutoEventTbl, (g_u8tAttrTable[a][1] & 0xFF), u8Temp, u16StartAddr & 0xFF, g_u8tAttrTable[a][2] & 0xFF);
                //改变起始地址
                g_u8tAttrTable[a][1] = (byte) u16StartAddr;
                //下一个开始地址
                u16StartAddr += g_u8tAttrTable[a][2];
            }
        }
        // 存放回数组
        System.arraycopy(u8Temp, 0, g_u8tAutoEventTbl, 0, u16StartAddr & 0xFF);
        //改变长度
        g_u8AutoEventTblUsed = (byte) u16StartAddr;
    }

    void advanceSettingNormalApply() {
        if (rb_advance_setting_normal.isChecked()) {
            if (rb_advance_setting_nor_single.isChecked()) {
                g_u8TempAttrTable[0] = 0;
                g_u8TempAttrTable[1] = 0;
                g_u8TempAttrTable[2] = 0;
                bIsSaveAttrTable = true;
            } else if (rb_advance_setting_nor_combo.isChecked()) {
                if (rb_adv_set_nor_combo_off.isChecked()) {
                    g_u8TempAttrTable[0] &= 0x3F;
                } else {
                    g_u8TempAttrTable[0] = (byte) (Transfer_Con.ATTR_AEV_ENABLE | Transfer_Con.ATTR_COMBO_KEY);
                    /*
                    for(int a=0;a<mGlobalVar.getDeviceMaxButton();a++)
                    {
                        mGlobalVar.coorTbl[(1+(g_u8ButtonID-Transfer_Con.TI_BUTTON_L1))*mGlobalVar.getDeviceMaxButton()*2+a*2] = 0x7FFF;
                        mGlobalVar.coorTbl[(1+(g_u8ButtonID-Transfer_Con.TI_BUTTON_L1))*mGlobalVar.getDeviceMaxButton()*2+a*2+1] = 0x7FFF;
                    }

                     */
                }
                g_u8TempAttrTable[1] = 0;
                g_u8TempAttrTable[2] = 0;
                bIsSaveAttrTable = true;
            }
            else if(rb_advance_setting_nor_continue.isChecked())
            {
                int time = sb_advance_setting_continue_inv.getProgress();
                if(time>2000)
                    time = 2000;
                g_u8TempAttrTable[0] = (byte) (Transfer_Con.ATTR_AEV_ENABLE | Transfer_Con.bContinueClick);
                g_u8TempAttrTable[1] = 0;
                g_u8TempAttrTable[2] = 2;
                g_u8TempAutoEventTbl[0] = (byte) (time/10);
                g_u8TempAutoEventTbl[1] = (byte)0xFF;
                g_u8ActionTblLen = 2;
                bIsSaveAttrTable = true;
                bIsSaveAutoEventTbl = true;
            }
        }
    }

    void advanceSettingFpsApply() {
        if (rb_advance_setting_fps_pull.isChecked()) {
            int time = sb_advance_setting_fps_start.getProgress();
            if (time > 120)
                time = 120;
            g_u8TempAutoEventTbl[0] = (byte) (time);

            time = sb_advance_setting_fps_inv.getProgress();
            if (time > 120)
                time = 120;
            g_u8TempAutoEventTbl[1] = (byte) (time);

            time = sb_advance_setting_fps_delta.getProgress();
            if (time > 100)
                time = 100;
            time = ((time * 0x7FFF + panelHeight / 2) / panelHeight);

            g_u8TempAutoEventTbl[2] = (byte) (time & 0xFF);
            g_u8TempAutoEventTbl[3] = 0;//(byte) (time & 0xFF);
            //g_u8TempAutoEventTbl[4] += (byte) ((time / 0x100) << 4);
            g_u8TempAutoEventTbl[4] += (byte) ((time / 0x100));

            g_u8TempAutoEventTbl[5] = (byte) (0xff);

            g_u8TempAttrTable[0] = (byte) (0x80 | Transfer_Con.bFPSPullGunDown);
            g_u8TempAttrTable[1] = 0;
            g_u8TempAttrTable[2] = 6;
            g_u8ActionTblLen = 6;
            bIsSaveAutoEventTbl = true;
            bIsSaveAttrTable = true;
        }
    }

    void advanceSettingMobaApply() {
        if (rb_advance_setting_moba_link.isChecked()) {

            if (ckb_adv_set_moba_dir_left.isChecked()) {
                g_u8TempAutoEventTbl[0] = (byte) 0x80;
            }
            if (ckb_adv_set_moba_dir_right.isChecked()) {
                g_u8TempAutoEventTbl[0] |= 0x40;
            }
            if(mGlobalVar.getIsSupportMenuKey()) {
                if (ckb_adv_set_moba_dir_flip.isChecked()) {
                    g_u8TempAutoEventTbl[0] |= 0x08;
                } else {
                    g_u8TempAutoEventTbl[0] &= 0xF7;
                }
            }

            g_u8TempAutoEventTbl[1] = (byte) 0xff;

            g_u8TempAttrTable[0] = (byte) (0x80 | Transfer_Con.bSkillWithDirect);
            g_u8TempAttrTable[1] = 0;
            g_u8TempAttrTable[2] = 2;
            g_u8ActionTblLen = 2;

            bIsSaveAutoEventTbl = true;
            bIsSaveAttrTable = true;
        } else if (rb_advance_setting_moba_cancel.isChecked()) {
            g_u8TempAttrTable[0] = (byte) (0x80 | Transfer_Con.bWZRYCancelConjure);
            bIsSaveAttrTable = true;
        } else if(rb_advance_setting_moba_range.isChecked())
        {
            g_u8TempAutoEventTbl[0] = (byte)(sb_advance_setting_moba_range.getProgress()&0xff);
            g_u8TempAutoEventTbl[1] = (byte)((sb_advance_setting_moba_range.getProgress()&0xff00)>>8);
            g_u8TempAutoEventTbl[2] = (byte)(sb_advance_setting_moba_range_delta.getProgress()&0xff);
            g_u8TempAutoEventTbl[3] = (byte)((sb_advance_setting_moba_range_delta.getProgress()&0xff00)>>8);
            g_u8TempAutoEventTbl[4] = (byte)0xFF;
            g_u8ActionTblLen = 5;
            g_u8TempAttrTable[0] = (byte) (0x80 | Transfer_Con.bFullRangeClick);
            g_u8TempAttrTable[1] = 0;
            g_u8TempAttrTable[2] = 5;
            bIsSaveAutoEventTbl = true;
            bIsSaveAttrTable = true;
        }
    }

    void advanceSettingSwipeApply() {
        long x, y, distance;
        y = pttbl_temp[g_u8ButtonID * 2] * panelHeight / 0x7FFF;
        x = pttbl_temp[g_u8ButtonID * 2 + 1] * panelWidth / 0x7FFF;
        distance = sb_advance_setting_swipe_sub.getProgress();
        if (distance < 100)
            distance = 100;
        if (rb_advance_setting_swipe_up.isChecked()) {
            y -= distance;
            if (y < 0)
                y = 0;
        } else if (rb_advance_setting_swipe_down.isChecked()) {
            y += distance;
            if (y > panelHeight)
                y = panelHeight;
        } else if (rb_advance_setting_swipe_left.isChecked()) {
            if (x >= distance)
                x -= distance;
            else
                x = 0;
        } else if (rb_advance_setting_swipe_right.isChecked()) {
            x += distance;
            if (x > panelWidth)
                x = panelWidth;
        } else if (rb_advance_setting_swipe_lu.isChecked()) {
            x -= (distance / 1.414f);
            if (x < 0)
                x = 0;
            y -= (distance / 1.414f);
            if (y < 0)
                y = 0;
        } else if (rb_advance_setting_swipe_ld.isChecked()) {
            x -= (distance / 1.414f);
            if (x < 0)
                x = 0;
            y += (distance / 1.414f);
            if (y > panelHeight)
                y = panelHeight;
        } else if (rb_advance_setting_swipe_ru.isChecked()) {
            x += (distance / 1.414f);
            if (x > panelWidth)
                x = panelWidth;
            y -= (distance / 1.414f);
            if (y < 0)
                y = 0;
        } else if (rb_advance_setting_swipe_rd.isChecked()) {
            x += (distance / 1.414f);
            if (x > panelWidth)
                x = panelWidth;
            y += (distance / 1.414f);
            if (y > panelHeight)
                y = panelHeight;
        }

        if (distance <= 100) {
            g_u8TempAutoEventTbl[0] = 5;
        } else {
            g_u8TempAutoEventTbl[0] = (byte) (distance / 20);
        }
        //Log.d(TAG,String.format("swipe End x=%d,y=%d,%d",x,y,(int)(distance/1.414)));
        y = (y * 0x7FFF + panelHeight / 2) / panelHeight;
        x = (x * 0x7FFF + panelWidth / 2) / panelWidth;

        // Log.d(TAG,String.format("swipe raw x=%d,y=%d",x,y));

        g_u8TempAutoEventTbl[1] = (byte) ((y & 0xff00) >> 8);
        g_u8TempAutoEventTbl[2] = (byte) (y & 0xff);
        g_u8TempAutoEventTbl[3] = (byte) ((x & 0xff00) >> 8);
        g_u8TempAutoEventTbl[4] = (byte) (x & 0xff);
        g_u8TempAutoEventTbl[5] = (byte) (0xff);

        g_u8TempAttrTable[0] = (byte) (0x80 | Transfer_Con.bSwipe);
        g_u8TempAttrTable[1] = 0;
        g_u8TempAttrTable[2] = 6;
        g_u8ActionTblLen = 6;

        bIsSaveAutoEventTbl = true;
        bIsSaveAttrTable = true;
    }

    void advanceSettingMacroApply() {

        int index =0;
        if(mGlobalVar.getIsSupportNewMacro_GP()) {
            if (rb_advance_setting_macro_virtual.isChecked()) {
                if (rb_advance_setting_macro_virtual_up.isChecked()) {
                    index = 0x80;
                } else if (rb_advance_setting_macro_virtual_loop.isChecked()) {
                    index = 0x40;
                }
            }
            else
            {
                if (rb_btn_advance_setting_macro_up.isChecked()) {
                    index = 0x80;
                } else if (rb_btn_advance_setting_macro_loop.isChecked()) {
                    index = 0x40;
                }
            }
        }

        Log.d(TAG,String.format("--------------1----=%x",index));

        if(!mGlobalVar.getIsSupportNewMacro_GP()) {
            if (g_u8ActionTblLen == 0)
                return;
        }
        else
        {
            if (g_u8ActionTblLen == 0)
            {

                if(((g_u8tAttrTable[g_u8ButtonID][0]&Transfer_Con.ATTR_MASK)==Transfer_Con.ATTR_MACRO)||((g_u8tAttrTable[g_u8ButtonID][0]&Transfer_Con.ATTR_MASK)==Transfer_Con.ATTR_MACRO_ADV))
                {
                    System.arraycopy(g_u8tAutoEventTbl,g_u8tAttrTable[g_u8ButtonID][1]&0xff,g_u8TempAutoEventTbl,2,g_u8tAttrTable[g_u8ButtonID][2]&0xff);
                    g_u8TempAutoEventTbl[0] = (byte)index;
                    g_u8ActionTblLen = (byte)((g_u8tAttrTable[g_u8ButtonID][2]&0xff) + 2);
                }
                else
                {
                   if(index!=(g_u8tAutoEventTbl[g_u8tAttrTable[g_u8ButtonID][1]&0xff]&0xff))
                   {
                       System.arraycopy(g_u8tAutoEventTbl,g_u8tAttrTable[g_u8ButtonID][1]&0xff,g_u8TempAutoEventTbl,0,g_u8tAttrTable[g_u8ButtonID][2]&0xff);
                       g_u8TempAutoEventTbl[0] = (byte)index;
                       g_u8ActionTblLen = (byte)(g_u8tAttrTable[g_u8ButtonID][2]&0xff);
                   }
                }

            }
            else
            {
                g_u8TempAutoEventTbl[0] = (byte)index;
            }
        }

        if(mGlobalVar.getIsSupportNewMacro_GP())
        {
            if (rb_advance_setting_macro_virtual.isChecked()) {
                g_u8TempAttrTable[2] = g_u8ActionTblLen;
                g_u8TempAttrTable[0] = (byte) (0x80 | Transfer_Con.ATTR_MACRO_ADV_NEW);
            } else {
                g_u8TempAttrTable[2] = g_u8ActionTblLen;
                g_u8TempAttrTable[0] = (byte) (0x80 | Transfer_Con.ATTR_MACRO_NEW);
            }
        }
        else {
            if (rb_advance_setting_macro_virtual.isChecked()) {
                g_u8TempAttrTable[2] = g_u8ActionTblLen;
                g_u8TempAttrTable[0] = (byte) (0x80 | Transfer_Con.ATTR_MACRO_ADV);
            } else {
                g_u8TempAttrTable[2] = g_u8ActionTblLen;
                g_u8TempAttrTable[0] = (byte) (0x80 | Transfer_Con.ATTR_MACRO);
            }
        }
        bIsSaveAutoEventTbl = true;
        bIsSaveAttrTable = true;
    }

    void advanceSettingConfirm() {

        if (rb_advance_setting_normal.isChecked()) {
            advanceSettingNormalApply();
        }
        if (rb_advance_setting_fps.isChecked()) {
            advanceSettingFpsApply();
        }
        if (rb_advance_setting_moba.isChecked()) {
            advanceSettingMobaApply();
        }
        if (rb_advance_setting_swipe.isChecked()) {
            advanceSettingSwipeApply();
        }
        if (rb_advance_setting_macro.isChecked()) {
            advanceSettingMacroApply();
        }
        if ((g_u8tAttrTable[g_u8ButtonID][0] & Transfer_Con.ATTR_MASK) != 0) {
            if ((g_u8tAttrTable[g_u8ButtonID][2] & 0xFF) >= (g_u8ActionTblLen&0xff)) {   // 原有空间 大于等于 现在空间
                g_u8tAttrTable[g_u8ButtonID][0] = g_u8TempAttrTable[0];
                g_u8tAttrTable[g_u8ButtonID][2] = g_u8ActionTblLen;
                System.arraycopy(g_u8TempAutoEventTbl, 0, g_u8tAutoEventTbl, (g_u8tAttrTable[g_u8ButtonID][1] & 0xFF), g_u8ActionTblLen & 0xFF);
                //g_u8AutoEventTblUsed+=g_u8ActionTblLen;
            } else {
                g_u8tAttrTable[g_u8ButtonID][0] = 0;
                reassignedAEVTbl();
                if ((g_u8ActionTblLen & 0xFF) + (g_u8AutoEventTblUsed & 0xFF) > Transfer_Con.MAX_AUTOEVENT_LENGTH) {
                    Toast.makeText(ButtonSettingService.this, getResources().getString(R.string.string_pop_button_setting_advance_total_event_buffer), Toast.LENGTH_SHORT).show();
                } else {
                    g_u8tAttrTable[g_u8ButtonID][0] = g_u8TempAttrTable[0];
                    g_u8tAttrTable[g_u8ButtonID][1] = g_u8AutoEventTblUsed;
                    g_u8tAttrTable[g_u8ButtonID][2] = g_u8ActionTblLen;
                    System.arraycopy(g_u8TempAutoEventTbl, 0, g_u8tAutoEventTbl, (g_u8AutoEventTblUsed & 0xFF), g_u8ActionTblLen & 0xFF);
                    g_u8AutoEventTblUsed = (byte) ((g_u8AutoEventTblUsed & 0xFF) + (g_u8ActionTblLen & 0xFF));
                }
            }
        } else {   // new
            Log.d(TAG, "new");
            reassignedAEVTbl();
            if ((g_u8ActionTblLen & 0xFF) + (g_u8AutoEventTblUsed & 0xFF) > Transfer_Con.MAX_AUTOEVENT_LENGTH) {
                    Toast.makeText(ButtonSettingService.this, getResources().getString(R.string.string_pop_button_setting_advance_total_event_buffer), Toast.LENGTH_SHORT).show();
            } else {
                g_u8tAttrTable[g_u8ButtonID][0] = g_u8TempAttrTable[0];
                g_u8tAttrTable[g_u8ButtonID][1] = g_u8AutoEventTblUsed;
                g_u8tAttrTable[g_u8ButtonID][2] = g_u8ActionTblLen;
                System.arraycopy(g_u8TempAutoEventTbl, 0, g_u8tAutoEventTbl, (g_u8AutoEventTblUsed & 0xFF), g_u8ActionTblLen & 0xFF);
                g_u8AutoEventTblUsed = (byte) ((g_u8AutoEventTblUsed & 0xFF) + (g_u8ActionTblLen & 0xFF));
            }
        }
        if(BuildConfig.DEBUG) {
            String str = "";
            for (int a = 0; a < (g_u8AutoEventTblUsed & 0xFF); a++)
                str += String.valueOf((int) g_u8tAutoEventTbl[a] & 0xff) + ",";
            Log.d(TAG, "Total: " + str);
            Log.d(TAG, "lenth: " + String.valueOf(g_u8AutoEventTblUsed & 0xff));
            str = "";
            for (int a = 0; a < (g_u8ActionTblLen & 0xff); a++)
                str += String.valueOf((int) g_u8TempAutoEventTbl[a] & 0xff) + ", ";
            Log.d(TAG, "Ev: " + String.valueOf(g_u8tAttrTable[g_u8ButtonID][0] & 0xff) + " start: " + String.valueOf(g_u8tAttrTable[g_u8ButtonID][1] & 0xff) + " len: " + String.valueOf(g_u8tAttrTable[g_u8ButtonID][2]) + " tbl: " + str);
        }

        if(Transfer_Con.ENABLE_GAME_DATA_IN_PHONE_GP)
        {

        }
        else
        {
            // 写回
            if (bIsSaveAutoEventTbl) {
                for (int a = 0; a < Transfer_Con.MAX_AUTOEVENT_LENGTH; a += 30) {
                    System.arraycopy(g_u8tAutoEventTbl, a, u8DataBuffer, 0, (a + 30 >= Transfer_Con.MAX_AUTOEVENT_LENGTH) ? (Transfer_Con.MAX_AUTOEVENT_LENGTH - a) : 30);
            /*
            str="";
            for(int t=0;t<((a+30>=Transfer_Con.MAX_AUTOEVENT_LENGTH)?(Transfer_Con.MAX_AUTOEVENT_LENGTH-a):30);t++)
                str+= String.valueOf((int)u8DataBuffer[t])+",";
            Log.d(TAG,"Total: "+str);
            */
                    if (mGlobalVar.tranSet_MultiValue(Transfer_Con.HID_CMD_SET_AEV_TBL, a, (a + 30 >= Transfer_Con.MAX_AUTOEVENT_LENGTH) ? (Transfer_Con.MAX_AUTOEVENT_LENGTH - a) : 30, u8DataBuffer)) {

                        bIsSaveAutoEventTbl = false;

                    }

                }
                if (mGlobalVar.tranSet_Value(Transfer_Con.HID_CMD_SAVE_DATA, 0, 0)) {
                    Log.d(TAG, "Aet write back ok: ");
                    if (!bIsSaveAutoEventTbl)
                        Toast.makeText(ButtonSettingService.this, getResources().getString(R.string.string_pop_file_save_success), Toast.LENGTH_SHORT).show();
                }

            }
            if (bIsSaveAttrTable) {
                for (int a = 0; a < 3; a++) {
                    for (int k = 0; k < mGlobalVar.getDeviceMaxButton(); k++) {
                        u8DataBuffer[k] = g_u8tAttrTable[k][a];
                    }

                    if (mGlobalVar.tranSet_MultiValue(Transfer_Con.HID_CMD_SET_KEY_ATTR, a, mGlobalVar.getDeviceMaxButton(), u8DataBuffer)) {

                        bIsSaveAttrTable = false;
                        //Toast.makeText(ButtonSettingService.this,"数据保存成功",Toast.LENGTH_SHORT).show();
                    }
                }
                for (int a = 0; a < mGlobalVar.getDeviceMaxButton(); a++) {
                    Log.d(TAG, String.format("%s=0x%x,0x%x,0x%x", Transfer_Con.tButtonName[a], g_u8tAttrTable[a][0], g_u8tAttrTable[a][1], g_u8tAttrTable[a][2]));
                }
                if (mGlobalVar.tranSet_Value(Transfer_Con.HID_CMD_SAVE_DATA, 0, 0)) {
                    Log.d(TAG, "attr write back ok: ");
                    if (!bIsSaveAttrTable)
                        Toast.makeText(ButtonSettingService.this, getResources().getString(R.string.string_pop_file_save_success), Toast.LENGTH_SHORT).show();
                }
            }
        }
    }

    void advanceSettingHideStep2() {
        layout_advance_setting_normal.setVisibility(View.GONE);
        layout_advance_setting_fps.setVisibility(View.GONE);
        layout_advance_setting_moba.setVisibility(View.GONE);
        layout_advance_setting_swipe.setVisibility(View.GONE);
        layout_advance_setting_macro.setVisibility(View.GONE);
        layout_advance_setting_quick_import.setVisibility(View.GONE);
        iv_btn_adv_range_bg.setVisibility(View.GONE);
    }

    void advanceSettingHideStep3() {
        layout_advance_setting_fps_pull.setVisibility(View.GONE);
        layout_advance_setting_moba_dir.setVisibility(View.GONE);
        layout_advance_setting_moba_range.setVisibility(View.GONE);
        layout_advance_setting_normal_single.setVisibility(View.GONE);
        layout_advance_setting_nor_combo.setVisibility(View.GONE);
        layout_advance_setting_normal_continue.setVisibility(View.GONE);
        layout_advance_setting_moba_cancel.setVisibility(View.GONE);
        layout_advance_setting_macro_btn.setVisibility(View.GONE);
        layout_advance_setting_macro_virtual.setVisibility(View.GONE);
        layout_advance_setting_swipe_sub.setVisibility(View.GONE);
        g_u8ActionTblLen = 0;
        iv_btn_adv_range_bg.setVisibility(View.GONE);
    }

    byte g_u8ToolBarPos = 0;
    private ImageLoader imageLoader = ImageLoader.getInstance();
    boolean g_bIsVirtualEdit = false;
    ArrayList<Uri> UriList;
    public void getImageUriList() {
    Uri mUri = Uri.parse("content://media/external/images/media");
    Uri mImageUri = null;
    Cursor cursor = getContentResolver().query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null,
            MediaStore.Images.Media.DEFAULT_SORT_ORDER);
    cursor.moveToFirst();
        UriList = new ArrayList<>();
    while(!cursor.isAfterLast())
    {

        int ringtoneID = cursor.getInt(cursor
                .getColumnIndex(MediaStore.MediaColumns._ID));
        mImageUri = Uri.withAppendedPath(mUri, "" + ringtoneID);
        //Log.d(TAG,mImageUri.toString());
        UriList.add(mImageUri);
        /*
        String data = cursor.getString(cursor
                .getColumnIndex(MediaStore.MediaColumns.DATA));

        if (picPath.equals(data)) {
            int ringtoneID = cursor.getInt(cursor
                    .getColumnIndex(MediaStore.MediaColumns._ID));
            mImageUri = Uri.withAppendedPath(mUri, "" + ringtoneID);
            break;
        }
        */
        cursor.moveToNext();
    }
}

    /**
     * ImageLoader 图片组件初始化
     *
     * @param context
     */
    public static void initImageLoader(Context context) {
        // This configuration tuning is custom. You can tune every option, you
        // may tune some of them,
        // or you can create default configuration by
        // ImageLoaderConfiguration.createDefault(this);
        // method.
        String path= Environment.getExternalStorageDirectory().getPath()+"/Image";
        File file=new File(path);
        ImageLoaderConfiguration config=new ImageLoaderConfiguration.Builder(context)
                .memoryCacheExtraOptions(200,200).memoryCacheSize(2*1024*1024)
                .threadPoolSize(3).threadPriority(1000).diskCache(new UnlimitedDiskCache(file))
                .diskCacheFileCount(50).diskCacheFileNameGenerator(new Md5FileNameGenerator()).
                        diskCacheSize(50*1024*1024).diskCacheFileCount(20).build();
        /*
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory().discCacheFileNameGenerator(new Md5FileNameGenerator()).tasksProcessingOrder(QueueProcessingType.LIFO)//.writeDebugLogs() // Remove
                // for
                // release
                // app
                .build();
        */
        // Initialize ImageLoader with configuration.
        ImageLoader.getInstance().init(config);
    }

    boolean g_bIsNewMacroEdit = false;

    void parseEvToList()
    {
        listData = new ArrayList<Map<String, Object>>();
        int start = 0;

        if(((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO_ADV_NEW)||((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO_NEW)) {
            start = 2;
            g_bIsNewMacroEdit =  true;
        }
        else
        {
            g_bIsNewMacroEdit = false;
        }
        if (((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO_ADV)||((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO_ADV_NEW)) {
            for (int a = start; a < (g_u8ActionTblLen&0xff); a += 5) {
                Map<String, Object> map = new HashMap<String, Object>();
                //Log.d(TAG,String.format("www 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, ",g_u8TempAutoEventTbl[a],g_u8TempAutoEventTbl[a+1],g_u8TempAutoEventTbl[a+2],g_u8TempAutoEventTbl[a+3],g_u8TempAutoEventTbl[a+4]));
                Log.d(TAG,String.format("------4------x=%x,=%x",g_u8TempAutoEventTbl[a],g_u8TempAutoEventTbl[a+1]));
                if ((g_u8TempAutoEventTbl[a] & 0x80) == 0x80) {
                    int x = ((g_u8TempAutoEventTbl[a] & 0xff) & 0x7f) * 256 + (g_u8TempAutoEventTbl[a + 1] & 0xff);
                    int y = ((g_u8TempAutoEventTbl[a + 2] & 0xff) & 0x7f) * 256 + (g_u8TempAutoEventTbl[a + 3] & 0xff);

                    x = (x * panelHeight +0x3FFF)/ 0x7FFF;
                    y = (y * panelWidth +0x3FFF)/ 0x7FFF;
                    map.put("id",0);
                    map.put("cr",(x<<16)+y);
                    map.put("btn",0xff);
                    map.put("act",0);
                } else if ((g_u8TempAutoEventTbl[a + 2] & 0x80) == 0x80) {
                    int x = ((g_u8TempAutoEventTbl[a] & 0xff) & 0x7f) * 256 + (g_u8TempAutoEventTbl[a + 1] & 0xff);
                    int y = ((g_u8TempAutoEventTbl[a + 2] & 0xff) & 0x7f) * 256 + (g_u8TempAutoEventTbl[a + 3] & 0xff);

                    x = (x * panelHeight +0x3FFF)/ 0x7FFF;
                    y = (y * panelWidth +0x3FFF)/ 0x7FFF;
                    map.put("id",0);
                    map.put("cr",(x<<16)+y);
                    map.put("btn",0xff);
                    map.put("act",2);

                } else {
                    int x = ((g_u8TempAutoEventTbl[a] & 0xff) & 0x7f) * 256 + (g_u8TempAutoEventTbl[a + 1] & 0xff);
                    int y = ((g_u8TempAutoEventTbl[a + 2] & 0xff) & 0x7f) * 256 + (g_u8TempAutoEventTbl[a + 3] & 0xff);

                    x = (x * panelHeight +0x3FFF)/ 0x7FFF;
                    y = (y * panelWidth +0x3FFF)/ 0x7FFF;
                    map.put("id",0);
                    map.put("cr",(x<<16)+y);
                    map.put("btn",0xff);
                    map.put("act",1);
                }
                if (g_u8TempAutoEventTbl[a + 4] == (byte) 0xFF) {
                    map.put("time",0xff);
                    listData.add(map);
                    break;
                }
                if (g_u8TempAutoEventTbl[a + 4] == 0) {
                    //str += getResources().getString(R.string.string_pop_button_setting_advance_event_same_time);
                    map.put("time",0);
                } else {
                    //str += getResources().getString(R.string.string_pop_button_setting_advance_event_wait) + String.valueOf((g_u8TempAutoEventTbl[a + 4] & 0xFF) * 10) + "ms, ";
                    map.put("time",(g_u8TempAutoEventTbl[a + 4] & 0xFF) * 10);
                }
                listData.add(map);
            }
        }
        else if (((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO)||((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO_NEW))
        {
            for (int a = start; a < (g_u8ActionTblLen&0xff); a += 2) {
                Map<String, Object> map = new HashMap<String, Object>();
                if ((g_u8TempAutoEventTbl[a] & 0x80) == 0x80) {
                    if (((g_u8TempAutoEventTbl[a] & 0x20) == 0x20)) {
                        if ((g_u8TempAutoEventTbl[a] & 0x10) == 0x10) {
                            map.put("id",0);
                            map.put("cr",0xffffffff);
                            map.put("btn",g_u8TempAutoEventTbl[a] & 0x0F);
                            map.put("act",0);
                            //str += "(R1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down);
                        } else {
                            //str += "(L1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down);
                            map.put("id",0);
                            map.put("cr",0xffffffff);
                            map.put("btn",g_u8TempAutoEventTbl[a] & 0x0F);
                            map.put("act",0);
                        }
                    } else {
                       // str += Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x3F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down_1);
                        map.put("id",0);
                        map.put("cr",0xffffffff);
                        map.put("btn",g_u8TempAutoEventTbl[a] & 0x3F);
                        map.put("act",0);
                    }
                } else if ((g_u8TempAutoEventTbl[a] & 0x40) == 0x40) {
                    if (((g_u8TempAutoEventTbl[a] & 0x20) == 0x20)) {
                        if ((g_u8TempAutoEventTbl[a] & 0x10) == 0x10) {
                            //str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + "(R1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + ")";
                            map.put("id",0);
                            map.put("cr",0xffffffff);
                            map.put("btn",g_u8TempAutoEventTbl[a] & 0x0F);
                            map.put("act",2);
                        } else {
                            //str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + "(L1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + ")";
                            map.put("id",0);
                            map.put("cr",0xffffffff);
                            map.put("btn",g_u8TempAutoEventTbl[a] & 0x0F);
                            map.put("act",2);
                        }
                    } else {
                        //str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x3F];
                        map.put("id",0);
                        map.put("cr",0xffffffff);
                        map.put("btn",g_u8TempAutoEventTbl[a] & 0x3F);
                        map.put("act",2);
                    }
                } else {
                    if (((g_u8TempAutoEventTbl[a] & 0x20) == 0x20)) {
                        if ((g_u8TempAutoEventTbl[a] & 0x10) == 0x10) {
                            //str += "(R1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up);
                            map.put("id",0);
                            map.put("cr",0xffffffff);
                            map.put("btn",g_u8TempAutoEventTbl[a] & 0x0F);
                            map.put("act",1);
                        } else {
                            //str += "(L1+" + Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up);
                            map.put("id",0);
                            map.put("cr",0xffffffff);
                            map.put("btn",g_u8TempAutoEventTbl[a] & 0x0F);
                            map.put("act",1);
                        }
                    } else {
                        //str += Transfer_Con.tButtonName[g_u8TempAutoEventTbl[a] & 0x3F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up_1);
                        map.put("id",0);
                        map.put("cr",0xffffffff);
                        map.put("btn",g_u8TempAutoEventTbl[a] & 0x3F);
                        map.put("act",1);
                    }
                }
                if (g_u8TempAutoEventTbl[a + 1] == (byte) 0xFF) {
                    map.put("time",0xff);
                    listData.add(map);
                    break;
                }
                if (g_u8TempAutoEventTbl[a + 1] == 0) {
                    //str += getResources().getString(R.string.string_pop_button_setting_advance_event_same_time);
                    map.put("time",0);
                } else {
                    //str += getResources().getString(R.string.string_pop_button_setting_advance_event_wait) + String.valueOf((g_u8TempAutoEventTbl[a + 1] & 0xff) * 10) + "ms, ";
                    map.put("time",(g_u8TempAutoEventTbl[a + 1] & 0xff) * 10);
                }
                listData.add(map);
            }
        }


        /*
        int index=0;
        listData = new ArrayList<Map<String, Object>>();
        if ((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO) {
            if (g_u8tAutoEventTbl[g_u8TempAttrTable[1] & 0xFF] == (byte) 0xFF)
                return;
            for (int a = 0; a < (g_u8TempAttrTable[2] & 0xFF); a += 2) {
                Map<String, Object> map = new HashMap<String, Object>();
                if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x80) == 0x80) {
                    if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x20) == 0x20) {
                        if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x10) == 0x10) {
                            map.put("id",index);
                            map.put("cr",0xffffffff);
                            map.put("btn",g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F);
                            map.put("act",0);
                            //str += "(R1" + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down);
                        } else {
                            map.put("id",index);
                            map.put("cr",0xffffffff);
                            map.put("btn",g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F);
                            map.put("act",0);
                            //str += "(L1" + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down);
                        }
                    } else {
                        map.put("id",index);
                        map.put("cr",0xffffffff);
                        map.put("btn",g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x3F);
                        map.put("act",0);
                        //str += Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x3F] + getResources().getString(R.string.string_pop_button_setting_advance_event_down_1);
                    }
                } else if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x40) == 0x40) {
                    if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x20) == 0x20) {
                        if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x10) == 0x10) {
                            map.put("id",index);
                            map.put("cr",0xffffffff);
                            map.put("btn",g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F);
                            map.put("act",2);
                            //str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + ")";
                        } else {
                            map.put("id",index);
                            map.put("cr",0xffffffff);
                            map.put("btn",g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F);
                            map.put("act",2);
                            //str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + ")";
                        }
                    } else {
                        map.put("id",index);
                        map.put("cr",0xffffffff);
                        map.put("btn",g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x3F);
                        map.put("act",2);
                        //str += getResources().getString(R.string.string_pop_button_setting_advance_event_swipe) + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x3F];
                    }
                } else {
                    if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x20) == 0x20) {
                        if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x10) == 0x10) {
                            map.put("id",index);
                            map.put("cr",0xffffffff);
                            map.put("btn",g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F);
                            map.put("act",1);
                            //str += "(R1" + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up);
                        } else {
                            //str += "(L1" + Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up);
                            map.put("id",index);
                            map.put("cr",0xffffffff);
                            map.put("btn",g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x0F);
                            map.put("act",1);
                        }
                    } else {
                        map.put("id",index);
                        map.put("cr",0xffffffff);
                        map.put("btn",g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x3F);
                        map.put("act",1);
                        //str += Transfer_Con.tButtonName[g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x3F] + getResources().getString(R.string.string_pop_button_setting_advance_event_up_1);
                    }
                }
                if (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] == (byte) 0xFF) {
                    map.put("time",0xff);
                    listData.add(map);
                    break;
                }
                if (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] == 0) {
                    map.put("time",0);
                    //str += getResources().getString(R.string.string_pop_button_setting_advance_event_same_time);
                } else {
                    map.put("time",(g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xFF) * 10);
                    //str += getResources().getString(R.string.string_pop_button_setting_advance_event_wait) + String.valueOf((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xFF) * 10) + "ms, ";
                }
                listData.add(map);
            }
        }
        else if ((g_u8TempAttrTable[0] & Transfer_Con.ATTR_MASK) == Transfer_Con.ATTR_MACRO_ADV) {
        if (g_u8tAutoEventTbl[g_u8TempAttrTable[1] & 0xFF] == (byte) 0xFF)
            return;
        for (int a = 0; a < (g_u8TempAttrTable[2] & 0xFF); a += 5) {
            Map<String, Object> map = new HashMap<String, Object>();
            if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0x80) == 0x80) {
                int x = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xff);
                int y = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 2] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 3] & 0xff);

                x = x * panelHeight / 0x7FFF;
                y = y * panelWidth / 0x7FFF;
                    //str += String.format("Coordinate(%d,%d)Press", y, x);
                    map.put("id",index);
                    map.put("cr",(y<<16)+x);
                    map.put("btn",0xff);
                    map.put("act",0);

            } else if ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 2] & 0x80) == 0x80) {
                int x = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xff);
                int y = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 2] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 3] & 0xff);

                x = x * panelHeight / 0x7FFF;
                y = y * panelWidth / 0x7FFF;
                    //str += String.format("滑至坐标(%d,%d)", y, x);
                map.put("id",index);
                map.put("cr",(y<<16)+x);
                map.put("btn",0xff);
                map.put("act",2);
            } else {
                int x = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 1] & 0xff);
                int y = ((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 2] & 0xff) & 0x7f) * 256 + (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 3] & 0xff);

                x = x * panelHeight / 0x7FFF;
                y = y * panelWidth / 0x7FFF;
                 //   str += String.format("坐标(%d,%d)松开", y, x);
                map.put("id",index);
                map.put("cr",(y<<16)+x);
                map.put("btn",0xff);
                map.put("act",1);
            }
            if (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 4] == (byte) 0xFF) {
                map.put("time",0xff);
                listData.add(map);
                break;
            }
            if (g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 4] == 0) {
                //str += getResources().getString(R.string.string_pop_button_setting_advance_event_same_time);
                map.put("time",0);
            } else {
                //str += getResources().getString(R.string.string_pop_button_setting_advance_event_wait) + String.valueOf((g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 4] & 0xFF) * 10) + "ms, ";
                map.put("time",(g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF) + a + 4] & 0xFF) * 10);
            }
            listData.add(map);
        }
    }*/
    }


    public View.OnClickListener advanceOnClickListener = new View.OnClickListener() {
        int width,height;
        @Override
        public void onClick(View v) {
            switch (v.getId())
            {
                case R.id.btn_advance_setting_cancel:

                    windowManager.removeView(layout_advance_setting);
                    bIsAdvanceSettingOn = false;

                    iv_btn_setting_ring.setX(iv_normal_btn[mBtnEditFlag-1].getX()-(mImgRingSize-mImageHalfSize));
                    iv_btn_setting_ring.setY(iv_normal_btn[mBtnEditFlag-1].getY()-(mImgRingSize-mImageHalfSize));
                    iv_btn_setting_ring.setVisibility(View.VISIBLE);
                    layout_button_setting_add_remove.setVisibility(View.VISIBLE);
                    bIsRecordMacro = false;
                    hideAllComboBtn(false);
                    showNormalEmptyBtn(true);
                    break;
                case R.id.btn_advance_setting_confirm:
                    advanceSettingConfirm();
                    btn_advance_setting_cancel.performClick();
                    break;
                case R.id.rb_advance_setting_normal:
                    advanceSettingHideStep2();
                    if(((mBtnEditFlag-1)>=Transfer_Con.TI_BUTTON_L1)&&((mBtnEditFlag-1)<=Transfer_Con.TI_BUTTON_R2))
                    {
                        rb_advance_setting_nor_combo.setVisibility(View.VISIBLE);
                    }
                    else
                    {
                        rb_advance_setting_nor_combo.setVisibility(View.GONE);
                    }
                    mAdvSettingStep1Index = 0;
                    layout_advance_setting_normal.setVisibility(View.VISIBLE);
                    rb_advance_setting_nor_single.setChecked(true);
                    rb_advance_setting_nor_single.performClick();
                    break;
                case R.id.rb_advance_setting_fps:
                    advanceSettingHideStep2();
                    mAdvSettingStep1Index = 2;
                    layout_advance_setting_fps.setVisibility(View.VISIBLE);
                    rb_advance_setting_fps_pull.setChecked(true);
                    rb_advance_setting_fps_pull.performClick();
                    break;
                case R.id.rb_advance_setting_moba:
                    advanceSettingHideStep2();
                    mAdvSettingStep1Index = 3;
                    layout_advance_setting_moba.setVisibility(View.VISIBLE);
                    rb_advance_setting_moba_link.setChecked(true);
                    rb_advance_setting_moba_link.performClick();
                    break;
                case R.id.rb_advance_setting_swipe:
                    advanceSettingHideStep2();
                    mAdvSettingStep1Index = 4;
                    layout_advance_setting_swipe.setVisibility(View.VISIBLE);
                    rb_advance_setting_swipe_up.setChecked(true);
                    rb_advance_setting_swipe_up.performClick();
                    showAdvSetSwipe();
                    break;
                case R.id.rb_advance_setting_macro:
                    advanceSettingHideStep2();
                    mAdvSettingStep1Index = 5;
                    layout_advance_setting_macro.setVisibility(View.VISIBLE);
                    rb_advance_setting_macro_btn_quick.setChecked(true);
                    rb_advance_setting_macro_btn_quick.performClick();
                    break;
                case R.id.rb_advance_setting_quick_import:
                    advanceSettingHideStep2();
                    advanceSettingHideStep3();
                    mAdvSettingStep1Index = 6;
                    layout_advance_setting_quick_import.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_quick_import));
                    break;

                case R.id.rb_advance_setting_nor_single:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 0;
                    layout_advance_setting_normal_single.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_single));
                    break;
                case R.id.rb_advance_setting_nor_combo:
                    advanceSettingHideStep3();
                    showAdvSetNorCombo();
                    mAdvSettingStep2Index = 1;
                    layout_advance_setting_nor_combo.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_combo));
                    break;
                case R.id.rb_advance_setting_nor_continue:
                    advanceSettingHideStep3();
                    showAdvSetNorContinue();
                    mAdvSettingStep2Index = 2;
                    layout_advance_setting_normal_continue.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_continue));
                    break;
                case R.id.rb_advance_setting_fps_pull:
                    advanceSettingHideStep3();
                    showAdvSetFPSPull();
                    mAdvSettingStep2Index = 0;
                    layout_advance_setting_fps_pull.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_fps_pull));
                    break;
                case R.id.rb_advance_setting_moba_link:
                    advanceSettingHideStep3();
                    showAdvSetMOBALink();
                    mAdvSettingStep2Index = 0;
                    layout_advance_setting_moba_dir.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_moba_link));
                    break;
                case R.id.rb_advance_setting_moba_range:
                    advanceSettingHideStep3();
                    showAdvSetMOBARange();
                    mAdvSettingStep2Index = 0;
                    layout_advance_setting_moba_range.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_moba_range));
                    break;
                case R.id.rb_advance_setting_moba_cancel:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 1;
                    layout_advance_setting_moba_cancel.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_moba_cancel));
                    break;
                case R.id.rb_advance_setting_swipe_up:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 0;
                    layout_advance_setting_swipe_sub.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_swipe_up));
                    break;
                case R.id.rb_advance_setting_swipe_down:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 1;
                    layout_advance_setting_swipe_sub.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_swipe_down));
                    break;
                case R.id.rb_advance_setting_swipe_left:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 2;
                    layout_advance_setting_swipe_sub.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_swipe_left));
                    break;
                case R.id.rb_advance_setting_swipe_right:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 3;
                    layout_advance_setting_swipe_sub.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_swipe_right));
                    break;
                case R.id.rb_advance_setting_swipe_lu:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 4;
                    layout_advance_setting_swipe_sub.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_swipe_lu));
                    break;
                case R.id.rb_advance_setting_swipe_ld:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 5;
                    layout_advance_setting_swipe_sub.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_swipe_ld));
                    break;
                case R.id.rb_advance_setting_swipe_ru:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 6;
                    layout_advance_setting_swipe_sub.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_swipe_ru));
                    break;
                case R.id.rb_advance_setting_swipe_rd:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 7;
                    layout_advance_setting_swipe_sub.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_swipe_rd));
                    break;
                case R.id.rb_advance_setting_macro_btn_quick:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 0;
                    showAdvSetMacroQuick();
                    layout_advance_setting_macro_btn.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_tip.setText(getResources().getString(R.string.string_pop_button_advance_macro_quick_tip));
                    tv_btn_setting_advance_msg.setText(getResources().getString(R.string.string_pop_button_setting_advance_macro));
                    btn_btn_setting_advance_next.setVisibility(View.INVISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_macro_quick));
                    break;
                case R.id.rb_advance_setting_macro_btn_adv:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 1;
                    showAdvSetMacroQuick();
                    mBtnActionFlag = 0;
                    layout_advance_setting_macro_btn.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_tip.setText(getResources().getString(R.string.string_pop_button_advance_macro_quick_tip));
                    tv_btn_setting_advance_msg.setText(getResources().getString(R.string.string_pop_button_setting_advance_macro));
                    btn_btn_setting_advance_next.setVisibility(View.INVISIBLE);
                    //layout_advance_setting_macro_btn.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_macro_adv));
                    break;
                case R.id.rb_advance_setting_macro_virtual:
                    advanceSettingHideStep3();
                    mAdvSettingStep2Index = 2;
                    showAdvSetVirtual();
                    layout_advance_setting_macro_virtual.setVisibility(View.VISIBLE);
                    tv_btn_setting_advance_detail.setText(getResources().getString(R.string.str_advance_setting_macro_virtual));
                    break;
                case R.id.btn_advance_setting_macro_btn_set:
                    windowManager.removeView(layout_advance_setting);
                    bIsAdvanceSettingOn = false;
                    //layout_btn_setting_advance.setVisibility(View.VISIBLE);
                    bIsRecordMacro = true;
                    iv_btn_setting_ring.setVisibility(View.VISIBLE);
                    mMacroBtnStep = 0;
                    if(mGlobalVar.getIsSupportNewMacro_GP())
                        g_u8ActionTblLen = 2;
                    else
                        g_u8ActionTblLen = 0;
                    btnSelectShow();
                    showNormalEmptyBtn(false);
                    hideAllComboBtn(true);
                    break;
                case R.id.btn_advance_setting_macro_virtual_set:
                    if (bIsDrawViewOn) {
                        windowManager.removeView(myDrawView);
                        bIsDrawViewOn = false;
                    }
                    windowManager.addView(button_setting_macro_virtual_bg_layout, paramsVirtualMacroBG);
                    if (!bIsDrawViewOn) {
                        windowManager.addView(myDrawView, paramsDraw);
                        myDrawView.g_u8VirtualMacroLen = 0;
                        bIsDrawViewOn = true;
                        myDrawView.g_bIsVirtualMacroMode = true;
                    }
                    if(mGlobalVar.getIsSupportNewMacro_GP())
                        g_u8ActionTblLen = 2;
                    else
                        g_u8ActionTblLen = 0;
                    windowManager.removeView(layout_advance_setting);
                    windowManager.removeView(btnFloatLayout);
                    windowManager.removeView(button_setting_layout);
                    windowManager.addView(usercombin_layout, paramsVirtualMacro);

                    ll_usercombin_toolbar.measure(0,0);
                    height = ll_usercombin_toolbar.getMeasuredHeight();

                    ll_usercombin_toolbar.setX(0);
                    ll_usercombin_toolbar.setY((panelHeight-height)/2);
                    if(g_u8ToolBarPos>0)
                        g_u8ToolBarPos--;
                    else
                        g_u8ToolBarPos = 5;
                    iv_usercombin_toolbar_pos.performClick();
                    break;
                case R.id.btn_advance_setting_macro_virtual_edit:
                    g_bIsVirtualEdit = true;
                case R.id.btn_advance_setting_macro_btn_edit:

                        windowManager.removeView(layout_advance_setting);
                        windowManager.removeView(btnFloatLayout);
                        windowManager.removeView(button_setting_layout);
                        windowManager.addView(layout_button_setting_macro_edit, paramsMacroEdit);
                        //System.arraycopy(g_u8TempAutoEventTbl, 0, g_u8tAutoEventTbl, (g_u8tAttrTable[g_u8ButtonID][1] & 0xFF), g_u8ActionTblLen & 0xFF);
                        g_u8ActionTblLen = g_u8TempAttrTable[2];
                        System.arraycopy(g_u8tAutoEventTbl, g_u8TempAttrTable[1] & 0xFF, g_u8TempAutoEventTbl, 0, g_u8ActionTblLen & 0xFF);
                        parseEvToList();
                        myEditAdapter = new MyEditAdapter();
                        lv_button_setting_macro_edit.setAdapter(myEditAdapter);

                    break;
                case R.id.btn_button_setting_macro_edit_cancel:
                    System.arraycopy(g_u8TempAutoEventTbl, 0, g_u8tAutoEventTbl, (g_u8tAttrTable[g_u8ButtonID][1] & 0xFF), g_u8ActionTblLen & 0xFF);
                case R.id.btn_button_setting_macro_edit_confirm:
                    windowManager.removeView(layout_button_setting_macro_edit);
                    windowManager.addView(button_setting_layout, paramsButtonSetting);
                    windowManager.addView(btnFloatLayout, paramsFloat);
                    windowManager.addView(layout_advance_setting, paramsAdvance);
                    if(g_bIsVirtualEdit)
                        tv_layout_advance_setting_macro_virtual_desc.setText(parseTempVirtualEvent());
                    else
                        tv_advance_setting_macro_btn_desc.setText(parseTempAutoEvent());
                    g_bIsVirtualEdit = false;
                    break;

                case R.id.rb_btn_setting_combine_press :
                    mu8BtnAction = 1;
                    btnDelayShow();
                    mBtnActionFlag|=1L<<g_u8EVKey;
                    break;
                case R.id.rb_btn_setting_combine_release :
                    mu8BtnAction = 2;
                    btnDelayShow();
                    mBtnActionFlag&=~(1L<<g_u8EVKey);
                    break;
                case R.id.rb_btn_setting_combine_swipe :
                    mu8BtnAction = 3;
                    btnDelayShow();
                    break;
                case R.id.rb_btn_setting_combine_same :
                    mu8BtnAction = 4;
                    btnDelayShow();
                    break;
                case R.id.btn_advance_setting_quick_import_load:
                case R.id.btn_advance_setting_macro_btn_import:
                    AlertDialog.Builder builder = new AlertDialog.Builder(ButtonSettingService.this);
                    builder.setTitle(getResources().getString(R.string.string_pop_reminder))
                            .setMessage(getResources().getString(R.string.string_pop_button_advance_import_reminder))
                            .setPositiveButton(getResources().getString(R.string.string_pop_continue), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    loadAEVData();
                                }
                            })
                            .setNegativeButton(getResources().getString(R.string.string_pop_no), new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                }
                            });
                    final AlertDialog dialog = builder.create();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                        if (Settings.canDrawOverlays(ButtonSettingService.this))
                            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
                    } else {
                        dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
                    }
                    dialog.show();

                    break;
                case R.id.btn_advance_setting_macro_btn_save:
                case R.id.btn_advance_setting_quick_import_save:
                    saveAVEData();
                    break;
                case R.id.btn_advance_setting_quick_import_recommend:
                    loadAEVFixData();
                    break;

                case  R.id.iv_usercombin_toolbar_pos:
                    g_u8ToolBarPos++;
                    if(g_u8ToolBarPos>=4)
                        g_u8ToolBarPos = 0;

                    if(g_u8ToolBarPos==1)
                    {
                        ll_usercombin_toolbar.setOrientation(LinearLayout.HORIZONTAL);
                        ll_usercombin_toolbar.measure(0,0);
                        width = ll_usercombin_toolbar.getMeasuredWidth();
                        height = ll_usercombin_toolbar.getMeasuredHeight();
                        ll_usercombin_toolbar.setX((panelWidth-width)/2);
                        ll_usercombin_toolbar.setY(0);
                        ll_usercombin_toolbar.setGravity(Gravity.CENTER_VERTICAL);
                        iv_usercombin_toolbar_pos.setImageDrawable(getResources().getDrawable(R.drawable.close_right));
                    }
                    else if(g_u8ToolBarPos==2)
                    {
                        ll_usercombin_toolbar.setOrientation(LinearLayout.VERTICAL);
                        ll_usercombin_toolbar.measure(0,0);
                        width = ll_usercombin_toolbar.getMeasuredWidth();
                        height = ll_usercombin_toolbar.getMeasuredHeight();
                        ll_usercombin_toolbar.setX((panelWidth-width));
                        ll_usercombin_toolbar.setY((panelHeight-height)/2);
                        ll_usercombin_toolbar.setGravity(Gravity.CENTER_HORIZONTAL);
                        iv_usercombin_toolbar_pos.setImageDrawable(getResources().getDrawable(R.drawable.close_bottom));
                    }
                    else if(g_u8ToolBarPos==3)
                    {
                        ll_usercombin_toolbar.setOrientation(LinearLayout.HORIZONTAL);
                        ll_usercombin_toolbar.measure(0,0);
                        width = ll_usercombin_toolbar.getMeasuredWidth();
                        height = ll_usercombin_toolbar.getMeasuredHeight();
                        ll_usercombin_toolbar.setX((panelWidth-width)/2);
                        ll_usercombin_toolbar.setY(panelHeight-height);
                        ll_usercombin_toolbar.setGravity(Gravity.CENTER_VERTICAL);
                        iv_usercombin_toolbar_pos.setImageDrawable(getResources().getDrawable(R.drawable.close_left));
                    }
                    else
                    {
                        ll_usercombin_toolbar.setOrientation(LinearLayout.VERTICAL);
                        ll_usercombin_toolbar.measure(0,0);
                        width = ll_usercombin_toolbar.getMeasuredWidth();
                        height = ll_usercombin_toolbar.getMeasuredHeight();
                        ll_usercombin_toolbar.setX(0);
                        ll_usercombin_toolbar.setY((panelHeight-height)/2);
                        ll_usercombin_toolbar.setGravity(Gravity.CENTER_HORIZONTAL);
                        iv_usercombin_toolbar_pos.setImageDrawable(getResources().getDrawable(R.drawable.close_top));
                    }
                        break;
                case  R.id.btn_usercombin_change_bg:

                    initImageLoader(ButtonSettingService.this);
                    getImageUriList();
                    //iv_usercombin_bg.setImageURI(UriList.get(0));
                    sv_usercombin_bg_list.setVisibility(View.VISIBLE);
                    gv_bg_iv_list.setAdapter(new MyAdapter(ButtonSettingService.this));

                    break;
                case  R.id.btn_usercombin_change_reset:
                    myDrawView.g_u8VirtualMacroLen = 0;
                    break;
                case  R.id.btn_usercombin_change_finish:
                    touch2AEVTbl();
                    if (bIsDrawViewOn) {
                        myDrawView.g_bIsVirtualMacroMode = false;
                        windowManager.removeView(myDrawView);
                        bIsDrawViewOn = false;
                    }
                    windowManager.removeView(usercombin_layout);
                    windowManager.removeView(button_setting_macro_virtual_bg_layout);
                    windowManager.addView(button_setting_layout, paramsButtonSetting);
                    windowManager.addView(btnFloatLayout, paramsFloat);
                    windowManager.addView(layout_advance_setting, paramsAdvance);

                    tv_layout_advance_setting_macro_virtual_desc.setText(parseTempVirtualEvent());
                    break;
                case R.id.btn_usercombin_bg_back:
                    sv_usercombin_bg_list.setVisibility(View.GONE);
                    break;
                case R.id.btn_usercombin_bg_alpha:
                    //iv_usercombin_bg.setAlpha(0);
                    iv_button_setting_macro_virtual_bg.setAlpha(0);
                    sv_usercombin_bg_list.setVisibility(View.GONE);
                    break;
            }
        }
    };


    String parseTempVirtualEvent()   //连招
    {
        String str = "";
            str = getResources().getString(R.string.string_pop_button_setting_advance_macro);
            for (int a = 2; a < (g_u8ActionTblLen&0xff); a += 5) {
                //Log.d(TAG,String.format("www 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, ",g_u8TempAutoEventTbl[a],g_u8TempAutoEventTbl[a+1],g_u8TempAutoEventTbl[a+2],g_u8TempAutoEventTbl[a+3],g_u8TempAutoEventTbl[a+4]));
                if ((g_u8TempAutoEventTbl[a] & 0x80) == 0x80) {
                    int x = ((g_u8TempAutoEventTbl[a] & 0xff) & 0x7f) * 256 + (g_u8TempAutoEventTbl[a + 1] & 0xff);
                    int y = ((g_u8TempAutoEventTbl[a + 2] & 0xff) & 0x7f) * 256 + (g_u8TempAutoEventTbl[a + 3] & 0xff);

                    x = (x * panelHeight +0x3FFF)/ 0x7FFF;
                    y = (y * panelWidth +0x3FFF)/ 0x7FFF;
                    if(mGlobalVar.getCurLanguageIndex()==1)
                        str += String.format("press at coordinate(%d,%d)", y, x);
                    else
                        str += String.format("坐标(%d,%d)按下", y, x);
                } else if ((g_u8TempAutoEventTbl[a + 2] & 0x80) == 0x80) {
                    int x = ((g_u8TempAutoEventTbl[a] & 0xff) & 0x7f) * 256 + (g_u8TempAutoEventTbl[a + 1] & 0xff);
                    int y = ((g_u8TempAutoEventTbl[a + 2] & 0xff) & 0x7f) * 256 + (g_u8TempAutoEventTbl[a + 3] & 0xff);

                    x = (x * panelHeight +0x3FFF)/ 0x7FFF;
                    y = (y * panelWidth +0x3FFF)/ 0x7FFF;
                    if(mGlobalVar.getCurLanguageIndex()==1)
                        str += String.format("swipe to coordinate(%d,%d)", y, x);
                    else
                        str += String.format("滑至坐标(%d,%d)", y, x);

                } else {
                    int x = ((g_u8TempAutoEventTbl[a] & 0xff) & 0x7f) * 256 + (g_u8TempAutoEventTbl[a + 1] & 0xff);
                    int y = ((g_u8TempAutoEventTbl[a + 2] & 0xff) & 0x7f) * 256 + (g_u8TempAutoEventTbl[a + 3] & 0xff);

                    x = (x * panelHeight +0x3FFF)/ 0x7FFF;
                    y = (y * panelWidth +0x3FFF)/ 0x7FFF;
                    if(mGlobalVar.getCurLanguageIndex()==1)
                        str += String.format("release at coordinate(%d,%d)", y, x);
                    else
                        str += String.format("坐标(%d,%d)松开", y, x);
                }
                if (g_u8TempAutoEventTbl[a + 4] == (byte) 0xFF) {
                    break;
                }
                if (g_u8TempAutoEventTbl[a + 4] == 0) {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_same_time);
                } else {
                    str += getResources().getString(R.string.string_pop_button_setting_advance_event_wait) + String.valueOf((g_u8TempAutoEventTbl[a + 4] & 0xFF) * 10) + "ms, ";
                }
            }
            str += ".";
        return str;
    }


    public void touch2AEVTbl()
    {
        int x=0,y=0;
        g_u8ActionTblLen = 2;
        for(int a=0;a<myDrawView.g_u8VirtualMacroLen;)
        {
            int pointCounter=((myDrawView.g_u32VirtualMacroData[a+3]&0xff0000)>>16);
            /*
            if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_HN2_INDEX) {

                if ((myDrawView.g_u32VirtualMacroData[a] & 0xff0000) == 0x10000) {
                    for (int k = 0; k < pointCounter; k += 6) {
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (0x80 | ((myDrawView.g_u32VirtualMacroData[a + k + 1] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((myDrawView.g_u32VirtualMacroData[a + k + 1] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (((myDrawView.g_u32VirtualMacroData[a + k + 2] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((myDrawView.g_u32VirtualMacroData[a + k + 2] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 0;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 5] = 0;
                        g_u8ActionTblLen += 6;
                    }
                    g_u8TempAutoEventTbl[g_u8ActionTblLen - 1] = 100;

                    for (int k = 0; k < pointCounter; k++) {
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (((myDrawView.g_u32VirtualMacroData[a + 4] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((myDrawView.g_u32VirtualMacroData[a + 4] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (((myDrawView.g_u32VirtualMacroData[a + 5] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((myDrawView.g_u32VirtualMacroData[a + 5] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 0;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 5] = 0;
                        g_u8ActionTblLen += 6;
                        a += 6;
                    }
                    g_u8TempAutoEventTbl[g_u8ActionTblLen - 1] = 100;
                } else {

                    if ((myDrawView.g_u32VirtualMacroData[a + 1] == myDrawView.g_u32VirtualMacroData[a + 4]) && (myDrawView.g_u32VirtualMacroData[a + 2] == myDrawView.g_u32VirtualMacroData[a + 5])) {
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (0x80 | ((myDrawView.g_u32VirtualMacroData[a + 1] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((myDrawView.g_u32VirtualMacroData[a + 1] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (((myDrawView.g_u32VirtualMacroData[a + 2] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((myDrawView.g_u32VirtualMacroData[a + 2] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 0;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 5] = 100;
                        g_u8ActionTblLen += 6;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (((myDrawView.g_u32VirtualMacroData[a + 4] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((myDrawView.g_u32VirtualMacroData[a + 4] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (((myDrawView.g_u32VirtualMacroData[a + 5] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((myDrawView.g_u32VirtualMacroData[a + 5] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 0;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 5] = 100;
                        g_u8ActionTblLen += 6;
                    } else {
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (0x80 | ((myDrawView.g_u32VirtualMacroData[a + 1] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((myDrawView.g_u32VirtualMacroData[a + 1] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (((myDrawView.g_u32VirtualMacroData[a + 2] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((myDrawView.g_u32VirtualMacroData[a + 2] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 0;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 5] = 100;
                        g_u8ActionTblLen += 6;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (((myDrawView.g_u32VirtualMacroData[a + 4] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((myDrawView.g_u32VirtualMacroData[a + 4] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (0x80 | ((myDrawView.g_u32VirtualMacroData[a + 5] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((myDrawView.g_u32VirtualMacroData[a + 5] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 0;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 5] = 100;
                        g_u8ActionTblLen += 6;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (((myDrawView.g_u32VirtualMacroData[a + 4] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((myDrawView.g_u32VirtualMacroData[a + 4] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (((myDrawView.g_u32VirtualMacroData[a + 5] & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((myDrawView.g_u32VirtualMacroData[a + 5] & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 0;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 5] = 100;
                        g_u8ActionTblLen += 6;
                    }
                    a += 6;
                }
            }
            else

             */
            {
                if ((myDrawView.g_u32VirtualMacroData[a] & 0xff0000) == 0x10000) {
                    for (int k = 0; k < pointCounter; k += 6) {
                        x = myDrawView.g_u32VirtualMacroData[a + k + 2]*0x7FFF/panelHeight;
                        y = myDrawView.g_u32VirtualMacroData[a + k + 1]*0x7FFF/panelWidth;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (0x80 | ((x & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((x & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (((y & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((y & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 0;
                        g_u8ActionTblLen += 5;
                    }
                    g_u8TempAutoEventTbl[g_u8ActionTblLen - 1] = 10;

                    for (int k = 0; k < pointCounter; k++) {
                        x = myDrawView.g_u32VirtualMacroData[a + 5]*0x7FFF/panelHeight;
                        y = myDrawView.g_u32VirtualMacroData[a + 4]*0x7FFF/panelWidth;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (((x & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((x & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (((y & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((y & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 0;
                        g_u8ActionTblLen += 5;
                        a += 6;
                    }
                    g_u8TempAutoEventTbl[g_u8ActionTblLen - 1] = 10;
                } else {
                    if ((myDrawView.g_u32VirtualMacroData[a + 1] == myDrawView.g_u32VirtualMacroData[a + 4]) && (myDrawView.g_u32VirtualMacroData[a + 2] == myDrawView.g_u32VirtualMacroData[a + 5])) {
                        x = myDrawView.g_u32VirtualMacroData[a + 2]*0x7FFF/panelHeight;
                        y = myDrawView.g_u32VirtualMacroData[a + 1]*0x7FFF/panelWidth;

                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (0x80 | ((x & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((x & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (((y & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((y & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 10;
                        g_u8ActionTblLen += 5;
                        x = myDrawView.g_u32VirtualMacroData[a + 5]*0x7FFF/panelHeight;
                        y = myDrawView.g_u32VirtualMacroData[a + 4]*0x7FFF/panelWidth;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (((x & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((x & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (((y & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((y & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 10;
                        g_u8ActionTblLen += 5;
                    } else {
                        x = myDrawView.g_u32VirtualMacroData[a + 2]*0x7FFF/panelHeight;
                        y = myDrawView.g_u32VirtualMacroData[a + 1]*0x7FFF/panelWidth;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (0x80 | ((x & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((x & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (((y & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((y & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 10;
                        g_u8ActionTblLen += 5;
                        x = myDrawView.g_u32VirtualMacroData[a + 5]*0x7FFF/panelHeight;
                        y = myDrawView.g_u32VirtualMacroData[a + 4]*0x7FFF/panelWidth;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (((x & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((x & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (0x80 | ((y & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((y & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 10;
                        g_u8ActionTblLen += 5;
                        g_u8TempAutoEventTbl[g_u8ActionTblLen] = (byte) (((x & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 1] = (byte) ((x & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 2] = (byte) (((y & 0x0000FF00) >> 8));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 3] = (byte) ((y & 0x000000FF));
                        g_u8TempAutoEventTbl[g_u8ActionTblLen + 4] = 10;
                        g_u8ActionTblLen += 5;
                    }
                    a += 6;
                }
            }
        }
    }

    ImageView iv_macro_edit_button_1;
    int button_sub =0xff;
    public void showMacroEditSetting(int pos)
    {
        int x=0,y=0;
        AlertDialog.Builder builder = new AlertDialog.Builder(ButtonSettingService.this);
        //EditText input = new EditText(ButtonSettingService.this);
        View view = LayoutInflater.from(ButtonSettingService.this).inflate(R.layout.button_setting_macro_edit_pop_layout, null, false);
        GridView gv_kb_function_select = view.findViewById(R.id.gv_button_setting_macro_edit_pop);
        ImageView iv_macro_edit_button = view.findViewById(R.id.iv_macro_edit_button);
        iv_macro_edit_button_1 = view.findViewById(R.id.iv_macro_edit_button_1);
        TextView tv_macro_edit_pop_coordinate_x = view.findViewById(R.id.tv_macro_edit_pop_coordinate_x);
        final EditText input_macro_edit_pop_coordinate_x = view.findViewById(R.id.input_macro_edit_pop_coordinate_x);
        TextView tv_macro_edit_pop_coordinate_y = view.findViewById(R.id.tv_macro_edit_pop_coordinate_y);
        final EditText input_macro_edit_pop_coordinate_y = view.findViewById(R.id.input_macro_edit_pop_coordinate_y);
        TextView tv_macro_edit_pop_time = view.findViewById(R.id.tv_macro_edit_pop_time);
        final EditText input_macro_edit_pop_time = view.findViewById(R.id.input_macro_edit_pop_time);
        LinearLayout ll_pop_macro_edit_virtual_x = view.findViewById(R.id.ll_pop_macro_edit_virtual_x);
        LinearLayout ll_pop_macro_edit_virtual_y = view.findViewById(R.id.ll_pop_macro_edit_virtual_y);
        LinearLayout ll_macro_edit_button = view.findViewById(R.id.ll_macro_edit_button);

        final LinearLayout gv_button_setting_macro_edit_pop_layout = view.findViewById(R.id.gv_button_setting_macro_edit_pop_layout);
        final List<Map<String, Object>> data_list;
        SimpleAdapter sim_adapter;
        data_list = new ArrayList<Map<String, Object>>();
        TypedArray ar;
        if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)
            ar = getResources().obtainTypedArray(R.array.gm1_button_images);
        else
            ar = getResources().obtainTypedArray(R.array.hn1_button_images);
        int len = ar.length();
        int[] resIds = new int[len];

        for(int a=0;a<len;a++)
        {
            Map<String, Object> map = new HashMap<String, Object>();
            resIds[a] = ar.getResourceId(a, 0);
            map.put("image", resIds[a]);
            map.put("id", a);
            data_list.add(map);
        }
        if(g_bIsVirtualEdit)
        {
            x = (int)listData.get(pos).get("cr");
            y = x >> 16;
            x= x & 0xffff;
            ll_macro_edit_button.setVisibility(View.GONE);
            tv_macro_edit_pop_coordinate_x.setText("X位置从"+String.valueOf(x));
            tv_macro_edit_pop_coordinate_y.setText("Y位置从"+String.valueOf(y));
            input_macro_edit_pop_coordinate_x.setText(String.valueOf(x));
            input_macro_edit_pop_coordinate_y.setText(String.valueOf(y));
        }
        else {
            iv_macro_edit_button.setImageResource(resIds[(int) listData.get(pos).get("btn")]);
            iv_macro_edit_button_1.setImageResource(resIds[(int) listData.get(pos).get("btn")]);
            ll_pop_macro_edit_virtual_x.setVisibility(View.GONE);
            ll_pop_macro_edit_virtual_y.setVisibility(View.GONE);

        }
        tv_macro_edit_pop_time.setText("时间从"+String.valueOf((int) listData.get(pos).get("time"))+"毫秒");
        input_macro_edit_pop_time.setText(String.valueOf((int) listData.get(pos).get("time")));
        String [] from ={"image"};
        int [] to = {R.id.iv_kb_gv};
        button_sub =  pos;
        sim_adapter = new SimpleAdapter(ButtonSettingService.this, data_list, R.layout.kb_function_select_gv_content, from, to);
        gv_kb_function_select.setAdapter(sim_adapter);
        gv_kb_function_select.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                gv_button_setting_macro_edit_pop_layout.setVisibility(View.GONE);
                TypedArray ar;
                if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)
                    ar = getResources().obtainTypedArray(R.array.gm1_button_images);
                else
                    ar = getResources().obtainTypedArray(R.array.hn1_button_images);
                int resIds = ar.getResourceId(position, 0);
                iv_macro_edit_button_1.setImageResource(resIds);
                button_sub = position;
                ar.recycle();
            }
        });


        ar.recycle();
        final int sub_x=x,sub_y=y,sub_pos=pos;
        builder.setView(view);
        builder.setTitle("特殊功能设置")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        int x = sub_x,y= sub_y;
                        //Log.d(TAG,String.format("------0------x=%d,y=%d",sub_x,sub_y));
                        int delay = 200;
                        int offset = 0;
                        if(g_bIsNewMacroEdit)
                            offset = 2;
                        if (!android.text.TextUtils.isEmpty(input_macro_edit_pop_time.getText())) {
                            delay = Integer.parseInt(input_macro_edit_pop_time.getText().toString());
                        }
                        if(g_bIsVirtualEdit) {
                            if (!android.text.TextUtils.isEmpty(input_macro_edit_pop_coordinate_x.getText())) {
                                x = Integer.parseInt(input_macro_edit_pop_coordinate_x.getText().toString());
                            }
                            if (!android.text.TextUtils.isEmpty(input_macro_edit_pop_coordinate_y.getText())) {
                                y = Integer.parseInt(input_macro_edit_pop_coordinate_y.getText().toString());
                            }
                            x = (x*0x7FFF+panelWidth/2)/panelWidth; ;
                            y = (y*0x7FFF+panelHeight/2)/panelHeight;
                            g_u8TempAutoEventTbl[offset+sub_pos*5] = (byte)((g_u8TempAutoEventTbl[offset+sub_pos*5]&0x80)| ((y & 0x0000FF00) >> 8));
                            g_u8TempAutoEventTbl[offset+sub_pos*5 + 1] = (byte) ((y & 0x000000FF));
                            g_u8TempAutoEventTbl[offset+sub_pos*5 + 2] = (byte) (((x & 0x0000FF00) >> 8));
                            g_u8TempAutoEventTbl[offset+sub_pos*5 + 3] = (byte) ((x & 0x000000FF));
                            g_u8TempAutoEventTbl[offset+sub_pos*5+4] = (byte)(delay/10);
                            //Log.d(TAG,String.format("------3------x=%x,=%x",g_u8TempAutoEventTbl[offset+sub_pos*5],g_u8TempAutoEventTbl[offset+sub_pos*5+1]));
                        }
                        else {
                            if (button_sub != sub_pos) {
                                g_u8TempAutoEventTbl[offset+sub_pos*2] =(byte) ((g_u8TempAutoEventTbl[offset+sub_pos*2]&0xC0) | button_sub);
                                g_u8TempAutoEventTbl[offset+sub_pos*2+1] = (byte)(delay/10);
                            }
                            else
                            {
                                g_u8TempAutoEventTbl[offset+sub_pos*2+1] = (byte)(delay/10);
                            }
                        }
                        parseEvToList();
                        myEditAdapter.notifyDataSetChanged();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
        final AlertDialog dialog = builder.create();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (Settings.canDrawOverlays(ButtonSettingService.this))
                dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
        } else {
            dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        }
        dialog.setCanceledOnTouchOutside(false);
        dialog.show();
        iv_macro_edit_button_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                gv_button_setting_macro_edit_pop_layout.setVisibility(View.VISIBLE);
            }
        });
    }

    class MyAdapter extends BaseAdapter {
        private Context context = null;

        public MyAdapter(Context context) {
            this.context = context;
        }

        @Override
        public int getCount() {
            return UriList.size();
        }

        @Override
        public Object getItem(int position) {
            return UriList.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder mHolder;
            final int pos = position;
            if (convertView == null) {
                mHolder = new ViewHolder();
                LayoutInflater inflater = LayoutInflater.from(context);
                //convertView = inflater.inflate(R.layout.listview_layout, null, true);
                convertView = inflater.inflate(R.layout.gridview_img_list, null, true);
                //mHolder.tv_lv_id = (TextView) convertView.findViewById(R.id.tv_lv_id);
                mHolder.imageView = (ImageView) convertView.findViewById(R.id.iv_gridview_icon);
                convertView.setTag(mHolder);
                convertView.setPadding(15, 15, 15, 15);  //每格的间距
            } else {
                mHolder = (ViewHolder) convertView.getTag();
            }
            mHolder.imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageLoader.displayImage(UriList.get(position).toString(),mHolder.imageView);
            //mHolder.imageView.setImageURI(UriList.get(position));

            mHolder.imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //iv_usercombin_bg.setAlpha(0xff);
                    //iv_usercombin_bg.setImageURI(UriList.get(pos));
                    iv_button_setting_macro_virtual_bg.setAlpha(0xff);
                    iv_button_setting_macro_virtual_bg.setImageURI(UriList.get(pos));
                    //gv_bg_iv_list.setVisibility(View.GONE);
                    sv_usercombin_bg_list.setVisibility(View.GONE);
                }
            });

            return convertView;
        }

        class ViewHolder {
            ImageView imageView;
        }
    }

    class MyEditAdapter extends BaseAdapter{
        @Override
        public int getCount() {
            return listData.size();
        }

        @Override
        public Object getItem(int position) {
            return listData.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder mHolder;
            final int pos = position;
            TypedArray ar;
            if(mGlobalVar.getDeviceIndex()==Transfer_Con.DEVICE_GM1_INDEX)
                ar = getResources().obtainTypedArray(R.array.gm1_button_images);
            else
                ar = getResources().obtainTypedArray(R.array.hn1_button_images);


            if (convertView == null) {
                mHolder = new ViewHolder();
                LayoutInflater inflater = LayoutInflater.from(ButtonSettingService.this);
                convertView = inflater.inflate(R.layout.listview_macro_edit_layout, null, true);
                mHolder.tv_step = convertView.findViewById(R.id.tv_macro_edit_step);
                mHolder.tv_coordinate = convertView.findViewById(R.id.tv_macro_edit_coordinate);
                mHolder.iv_button = convertView.findViewById(R.id.iv_macro_edit_button);
                mHolder.tv_action = convertView.findViewById(R.id.tv_macro_edit_action);
                mHolder.tv_time = convertView.findViewById(R.id.tv_macro_edit_time);
                mHolder.btn_edit = convertView.findViewById(R.id.btn_macro_edit_modify);
                convertView.setTag(mHolder);
            } else {
                mHolder = (ViewHolder) convertView.getTag();
            }
            mHolder.tv_step.setText(String.valueOf(pos+1));
            if((int)listData.get(pos).get("btn")==0xff)
            {
                int x = (int)listData.get(pos).get("cr");
                int y = x >> 16;
                x = x & 0xffff;
                mHolder.tv_coordinate.setText(String.format("坐标(%d,%d)",x,y));
            }
            else //if((int)listData.get(pos).get("btn")!=0xff)
            {
                int resIds = ar.getResourceId((int) listData.get(pos).get("btn"), 0);
                mHolder.iv_button.setImageResource(resIds);
            }
            if((int)listData.get(pos).get("act")==1)
            {
                mHolder.tv_action.setText("松开");
            }
            else if((int)listData.get(pos).get("act")==2)
            {
                mHolder.tv_action.setText("滑至");
            }
            else
            {
                mHolder.tv_action.setText("按下");
            }
            if((int)listData.get(pos).get("time")==0xff)
                mHolder.tv_time.setText("结束");
            else
                mHolder.tv_time.setText(String.valueOf((int)listData.get(pos).get("time"))+"毫秒");
            ar.recycle();

            mHolder.btn_edit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    showMacroEditSetting(pos);
                }
            });
            return convertView;
        }

        class ViewHolder {
            TextView tv_step;
            TextView tv_coordinate;
            ImageView iv_button;
            TextView tv_action;
            TextView tv_time;
            Button btn_edit;
        }
    };

    @Override
    public void onDestroy()
    {
        if(Transfer_Con.ENABLE_S2_MENU_COVER&&(mGlobalVar.getIsForceS2Enable()))
        {

        }
        else
        {
            if (Transfer_Con.ENABLE_S2_QUICK_MENU || Transfer_Con.ENABLE_GN_LOGO_QUICK_MENU) {
                if (mGlobalVar.getIsSupportMenuKey()) {
                    if (bIsNeedCloseMenu) {
                        mGlobalVar.tranSet_Value(Transfer_Con.HID_CMD_SET_MENU_POS, 0, 0);
                    }
                }
            }
        }
        if(Transfer_Con.ENABLE_OPPO_MSG_HANDLE) {
            if (android.os.Build.BRAND.equalsIgnoreCase("OPPO")) {
                handlerSystem.removeMessages(0);
            }
        }
        if(bIsBroadcastOn)
            unregisterReceiver(myBroadcastReceive);
        if(bIsShow)
            windowManager.removeView(button_setting_layout);
        windowManager.removeView(btnFloatLayout);
        if(bIsDrawViewOn)
            windowManager.removeView(myDrawView);
        if(bIsAdvanceSettingOn)
            windowManager.removeView(layout_advance_setting);
        mGlobalVar.setIsSettingServiceRunning(false);
        super.onDestroy();
    }

    void saveAVEData()
    {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED)
        {
            Toast.makeText(ButtonSettingService.this, getResources().getString(R.string.string_pop_float_menu_save_fail_permitted), Toast.LENGTH_SHORT).show();
        }
        else
        {
            final String strDefFileName = Transfer_Con.tButtonName[mBtnEditFlag-1]+getResources().getString(R.string.string_pop_button_advance_title_attr);
            AlertDialog.Builder builder = new AlertDialog.Builder(ButtonSettingService.this);
            final EditText editText = new EditText(ButtonSettingService.this);
            editText.setHint(strDefFileName);
            editText.setSingleLine();
            builder.setTitle(getResources().getString(R.string.string_pop_button_advance_export_key_attr))
                    .setView(editText)
                    .setMessage(getResources().getString(R.string.string_pop_data_save_dialog_input_filename))
                    .setPositiveButton(getResources().getString(R.string.string_pop_confirm), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            String strFileName = strDefFileName;

                            if (!android.text.TextUtils.isEmpty(editText.getText()))
                                strFileName = editText.getText().toString();
                            strFileName += ".kae";

                            JSONArray jsonArray = new JSONArray();
                                jsonArray.put(g_u8TempAttrTable[0]);
                                jsonArray.put(g_u8TempAttrTable[1]);
                                jsonArray.put(g_u8TempAttrTable[2]);
                            for (int a=0;a<g_u8TempAttrTable[2]; a++) {
                                jsonArray.put(g_u8tAutoEventTbl[(g_u8TempAttrTable[1] & 0xFF)+a]);
                            }
                            if (mGlobalVar.writeFile(strFileName, jsonArray.toString())) {
                                Toast.makeText(ButtonSettingService.this, strFileName + getResources().getString(R.string.string_pop_file_save_success), Toast.LENGTH_SHORT).show();
                            }
                        }
                    })
                    .setNegativeButton(getResources().getString(R.string.string_pop_cancel), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    });
            final AlertDialog dialog = builder.create();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (Settings.canDrawOverlays(ButtonSettingService.this))
                    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
            } else {
                dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            }
            dialog.show();
        }
    }

    void loadAEVData()
    {
        if (Build.VERSION.SDK_INT >= 26 && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(ButtonSettingService.this, getResources().getString(R.string.string_pop_float_menu_save_fail_permitted), Toast.LENGTH_SHORT).show();
        } else {
            ArrayList<String> fileList = mGlobalVar.getFileList("kae");
            final String[] item = new String[fileList.size()];
            for(int a=0;a<fileList.size();a++)
                item[a] = fileList.get(a);

            AlertDialog.Builder builder = new AlertDialog.Builder(ButtonSettingService.this);
            builder.setTitle(getResources().getString(R.string.string_pop_data_save_dialog_input_filename))
                    .setItems(item, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //Toast.makeText(MainActivity.this,String.valueOf(which),Toast.LENGTH_SHORT).show();
                            String fileName = item[which];
                            String content = mGlobalVar.readFile(fileName);
                            byte[] u8temp = new byte[Transfer_Con.MAX_AUTOEVENT_LENGTH];
                            try {
                                JSONArray jsonArray = new JSONArray(content);
                                for(int a=0;a<3;a++)
                                {
                                    g_u8TempAttrTable[a] = (byte)jsonArray.getInt(a);
                                }
                                for(int a=3;a<jsonArray.length();a++)
                                {
                                    u8temp[a-3] = (byte)jsonArray.getInt(a);
                                }
                                if(mGlobalVar.getIsSupportNewMacro_GP()) {
                                    if((g_u8TempAttrTable[0]==Transfer_Con.ATTR_MACRO)||(g_u8TempAttrTable[0]==Transfer_Con.ATTR_MACRO_ADV))
                                    {
                                        g_u8TempAttrTable[0] =(byte)(g_u8TempAttrTable[0]|0x10);
                                        System.arraycopy(u8temp,0,g_u8TempAutoEventTbl,2,g_u8TempAttrTable[2]);
                                        g_u8TempAttrTable[2]+=2;
                                        g_u8TempAutoEventTbl[0] = 0x00;
                                        g_u8TempAutoEventTbl[1] = 0x00;
                                    }
                                    else
                                    {
                                        System.arraycopy(u8temp,0,g_u8TempAutoEventTbl,0,g_u8TempAttrTable[2]);
                                    }
                                }
                                else
                                {
                                    System.arraycopy(u8temp,0,g_u8TempAutoEventTbl,0,g_u8TempAttrTable[2]);
                                }

                                g_u8TempAttrTable[0] =(byte)(g_u8TempAttrTable[0]|0x80);
                                g_u8ActionTblLen=g_u8TempAttrTable[2];

                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                           // tv_advance_setting_macro_btn_desc.setText(parseTempAutoEvent());
                            bIsSaveAttrTable = true;
                            bIsSaveAutoEventTbl = true;
                            advanceSettingConfirm();

                        }
                    });
            final AlertDialog dialog = builder.create();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (Settings.canDrawOverlays(ButtonSettingService.this))
                    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
            } else {
                dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            }
            dialog.show();
        }
    }
    String[] files;
    public String[] getfileFromAssets(String path) {
        AssetManager assetManager = ButtonSettingService.this.getAssets();
        try {
            files = assetManager.list(path);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return files;
    }



    void loadAEVFixData()
    {
        if (Build.VERSION.SDK_INT >= 26 && checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)
                != PackageManager.PERMISSION_GRANTED) {
            Toast.makeText(ButtonSettingService.this, getResources().getString(R.string.string_pop_float_menu_save_fail_permitted), Toast.LENGTH_SHORT).show();
        } else {

            String str="wzry";
            if(Transfer_Con.ENABLE_GAME_DATA_IN_PHONE_GP)
            {
                if(mGlobalVar.curPkgName.contains(Transfer_Con.defPackageName[0]))
                {
                    str = "hpjy";
                }
                else
                {
                    str = "wzry";
                }
            }
            else {
                if (mGlobalVar.getmCurGame() == 0) {
                    str = "hpjy";
                } else {
                    str = "wzry";
                }
            }
            files = getfileFromAssets(str);
            final String strSub= str;
            final String[] item = new String[files.length];
            System.arraycopy(files,0,item,0,files.length);

            AlertDialog.Builder builder = new AlertDialog.Builder(ButtonSettingService.this);
            builder.setTitle(getResources().getString(R.string.string_pop_data_save_dialog_input_filename))
                    .setItems(item, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            String fileName =strSub+"/"+ item[which];
                            //String content = mGlobalVar.readFile(fileName);
                            //Toast.makeText(ButtonSettingService.this,fileName,Toast.LENGTH_SHORT).show();
                            if(BuildConfig.DEBUG)
                                Log.d(TAG,fileName);
                            String content = null;
                            InputStream is = null;
                            byte[] u8temp = new byte[Transfer_Con.MAX_AUTOEVENT_LENGTH];
                            try {

                                is = getResources().getAssets().open(fileName);
                                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                byte[] buffer = new byte[1024];
                                int len = -1;
                                while ((len = is.read(buffer)) != -1) {
                                    baos.write(buffer, 0, len);
                                }
                                content = baos.toString();
                                is.close();
                            } catch (FileNotFoundException e) {
                                e.printStackTrace();
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                            try {
                                JSONArray jsonArray = new JSONArray(content);
                                for(int a=0;a<3;a++)
                                {
                                    g_u8TempAttrTable[a] = (byte)jsonArray.getInt(a);
                                }
                                for(int a=3;a<jsonArray.length();a++)
                                {
                                    u8temp[a-3] = (byte)jsonArray.getInt(a);
                                }

                                if(mGlobalVar.getIsSupportNewMacro_GP()) {
                                    if((g_u8TempAttrTable[0]==Transfer_Con.ATTR_MACRO)||(g_u8TempAttrTable[0]==Transfer_Con.ATTR_MACRO_ADV))
                                    {
                                        g_u8TempAttrTable[0] =(byte)(g_u8TempAttrTable[0]|0x10);
                                        System.arraycopy(u8temp,0,g_u8TempAutoEventTbl,2,g_u8TempAttrTable[2]);
                                        g_u8TempAttrTable[2]+=2;
                                        g_u8TempAutoEventTbl[0] = 0x00;
                                        g_u8TempAutoEventTbl[1] = 0x00;
                                    }
                                    else
                                    {
                                        System.arraycopy(u8temp,0,g_u8TempAutoEventTbl,0,g_u8TempAttrTable[2]);
                                    }
                                }
                                else
                                {
                                    System.arraycopy(u8temp,0,g_u8TempAutoEventTbl,0,g_u8TempAttrTable[2]);
                                }

                                g_u8TempAttrTable[0] =(byte)(g_u8TempAttrTable[0]|0x80);
                                g_u8ActionTblLen=g_u8TempAttrTable[2];

                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            // tv_advance_setting_macro_btn_desc.setText(parseTempAutoEvent());
                            bIsSaveAttrTable = true;
                            bIsSaveAutoEventTbl = true;
                            advanceSettingConfirm();
                        }
                    });
            final AlertDialog dialog = builder.create();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                if (Settings.canDrawOverlays(ButtonSettingService.this))
                    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY);
            } else {
                dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
            }
            dialog.show();
        }
    }



    class MyBroadcastReceive extends BroadcastReceiver
    {
        @Override
        public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub

            Configuration mConfiguration = context.getResources().getConfiguration(); //获取设置的配置信息
            int ori = mConfiguration.orientation; //获取屏幕方向
            if (ori == Configuration.ORIENTATION_LANDSCAPE) {
                //横屏
                Log.d(TAG,"横屏 "+String.valueOf(ori));
            } else if (ori == Configuration.ORIENTATION_PORTRAIT) {
                //竖屏
                Log.d(TAG,"竖屏 "+String.valueOf(ori));
                stopSelf();
            }
            String action=intent.getAction();
            if(UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action))
            {
                mGlobalVar.setbIsUsbConnect(false);
                mGlobalVar.setbIsTransferMode(false);
                mGlobalVar.myUsbDevice = null;
                mGlobalVar.myInterface = null;
                mGlobalVar.epOut = null;
                mGlobalVar.epIn = null;
                if(Transfer_Con.ENABLE_OPPO_MSG_HANDLE) {
                    if (android.os.Build.BRAND.equalsIgnoreCase("OPPO")) {
                        mGlobalVar.setIsFloatServiceRunning(false);
                    }
                }
                stopSelf();
            }

            if("com.opd.soeghtool.content".equals(action))
            {
                windowManager.removeView(button_setting_layout);
                if(!bIsDrawViewOn) {
                    windowManager.addView(myDrawView, paramsDraw);
                    bIsDrawViewOn = true;
                }
                windowManager.addView(button_setting_layout,paramsButtonSetting);
                btn_btn_setting_guide.setVisibility(View.VISIBLE);
                String name = intent.getStringExtra("Guide");
                if(name.equals("Setting"))
                {
                    SharedPreferences.Editor editor = getSharedPreferences(Transfer_Con.SAVENAME, MODE_PRIVATE).edit();
                    editor.putBoolean("AdvSetGuide", mGlobalVar.getIsAdvSetNeedGuide());
                    Log.d(TAG,"AdvSetGuide " +String.valueOf(mGlobalVar.getIsAdvSetNeedGuide()));
                    editor.apply();
                }
            }

        }
    }
}
/*-------------------------------------------------------end of File-------------------------------------------------- */